to avoid sharing substructure with the lower-level indexquals. This is
currently only an issue if there are SubPlans in the indexquals, which is
uncommon but not impossible --- see bug #2218 reported by Nicholas Vinen.
We use the same kluge for indexqual vs indexqualorig in the index scans
themselves ... would be nice to clean this up someday.
*/
bitmapqualorig = list_difference_ptr(bitmapqualorig, qpqual);
+ /*
+ * Copy the finished bitmapqualorig to make sure we have an independent
+ * copy --- needed in case there are subplans in the index quals
+ */
+ bitmapqualorig = copyObject(bitmapqualorig);
+
/* Finally ready to build the plan node */
scan_plan = make_bitmap_heapscan(tlist,
qpqual,