[ a bit off-topic for the thread, but ... ]
"Kevin Grittner" <Kevin.Grittner@wicourts.gov> writes:
> I'll attach the query and plan. You'll note that the query looks a
> little odd, especially all the (1=1) tests.
FWIW, it would be better to use "TRUE" as a placeholder in your
generated queries. I don't suppose this would make a huge percentage
difference in such complicated queries, but in and of itself there are
a lot of cycles spent to parse "1=1" and then reduce it to constant TRUE.
regards, tom lane