Patch requires further polishing including comments, minor refactoring etc. I'm going to continue work on this.
I also run the same performance comparison as Nikita [1] on my laptop.
The results are shown below. PostgreSQL was built with -O2 and
asserts enabled.
| Query time, ms | WHERE condition | master | patch | ---------------------------------------+--------+-------+ a @> '{}' | 117 | 116 | a @> '{}' and b @> '{}' | 150 | 146 | a @> '{}' and b @> '{}' and c @> '{}' | 168 | 167 | a @> '{}' and a @@ '1' | 126 | 0.6 | a @> '{}' and a @@ '-1' | 128 | 3.2 | a @@ '!-1' and a @@ '1' | 127 | 0.7 | a @@ '!1' and a @@ '-1' | 122 | 4.4 |
Performance effect looks similar to patch #4 by Nikita. I've tried to
add patch #4 to comparison, but I've catch assertion failure.