@@ -250,16 +250,18 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path)
250250
251251if (jsq -> type == jqiGreater || jsq -> type == jqiGreaterOrEqual )
252252{
253+ result -> bounds .leftBound = (JsQueryItem * )palloc (sizeof (JsQueryItem ));
253254result -> bounds .leftInclusive = (jsq -> type == jqiGreaterOrEqual );
254255result -> bounds .rightBound = NULL ;
255- result -> bounds .leftBound = ( JsQueryItem * ) palloc ( sizeof ( JsQueryItem )) ;
256+ result -> bounds .rightInclusive = false ;
256257jsqGetArg (jsq ,result -> bounds .leftBound );
257258}
258259else
259260{
261+ result -> bounds .rightBound = (JsQueryItem * )palloc (sizeof (JsQueryItem ));
260262result -> bounds .rightInclusive = (jsq -> type == jqiLessOrEqual );
261263result -> bounds .leftBound = NULL ;
262- result -> bounds .rightBound = ( JsQueryItem * ) palloc ( sizeof ( JsQueryItem )) ;
264+ result -> bounds .leftInclusive = false ;
263265jsqGetArg (jsq ,result -> bounds .rightBound );
264266}
265267return result ;
@@ -699,12 +701,13 @@ makeEntries(ExtractedNode *node, MakeEntryHandler handler, Pointer extra)
699701for (i = 0 ;i < node -> args .count ;i ++ )
700702{
701703child = node -> args .items [i ];
702- if (!child )continue ;
703- if (child -> sClass > node -> sClass && !child -> forceIndex )
704- {
705- Assert (node -> type != eOr );
704+ if (!child )
705+ continue ;
706+ /* Skip non-selective AND children */
707+ if (child -> sClass > node -> sClass &&
708+ node -> type == eAnd &&
709+ !child -> forceIndex )
706710continue ;
707- }
708711child = makeEntries (child ,handler ,extra );
709712if (child )
710713{
@@ -771,15 +774,15 @@ setSelectivityClass(ExtractedNode *node, CheckEntryHandler checkHandler,
771774if (!child )
772775continue ;
773776
777+ setSelectivityClass (child ,checkHandler ,extra );
778+
774779if (!isLogicalNodeType (child -> type ))
775780{
776781if (child -> hint == jsqNoIndex ||
777782!checkHandler (child ,extra ))
778783continue ;
779784}
780785
781- setSelectivityClass (child ,checkHandler ,extra );
782-
783786if (child -> forceIndex )
784787node -> forceIndex = true;
785788