@@ -812,6 +812,7 @@ make_hash_entry_handler(ExtractedNode *node, Pointer extra)
812812GINKey * key ;
813813KeyExtra * keyExtra ;
814814int result ;
815+ bool partialMatch = false;
815816
816817Assert (node -> type == eScalar );
817818
@@ -827,11 +828,23 @@ make_hash_entry_handler(ExtractedNode *node, Pointer extra)
827828if (!node -> bounds .inequality )
828829{
829830if (node -> bounds .exact -> type == jqiAny )
830- return -1 ;
831- key = make_gin_query_key (node -> bounds .exact ,hash );
831+ {
832+ JsQueryValue value ;
833+ value .jqBase = NULL ;
834+ value .jqPos = 0 ;
835+ value .type = jqiNull ;
836+ key = make_gin_query_key (& value ,hash );
837+ partialMatch = true;
838+ keyExtra -> lossy = true;
839+ }
840+ else
841+ {
842+ key = make_gin_query_key (node -> bounds .exact ,hash );
843+ }
832844}
833845else
834846{
847+ partialMatch = true;
835848if (node -> bounds .leftBound )
836849{
837850key = make_gin_query_key (node -> bounds .leftBound ,hash );
@@ -852,8 +865,7 @@ make_hash_entry_handler(ExtractedNode *node, Pointer extra)
852865keyExtra -> rightBound = NULL ;
853866}
854867}
855- result = add_entry (e ,PointerGetDatum (key ), (Pointer )keyExtra ,
856- node -> bounds .inequality );
868+ result = add_entry (e ,PointerGetDatum (key ), (Pointer )keyExtra ,partialMatch );
857869return result ;
858870}
859871
@@ -893,7 +905,11 @@ gin_compare_partial_jsonb_hash_value(PG_FUNCTION_ARGS)
893905{
894906KeyExtra * extra_data = (KeyExtra * )PG_GETARG_POINTER (3 );
895907
896- if (extra_data -> inequality )
908+ if (extra_data -> lossy )
909+ {
910+ result = 0 ;
911+ }
912+ else if (extra_data -> inequality )
897913{
898914result = 0 ;
899915if (!extra_data -> leftInclusive && compare_gin_key_value (key ,partial_key ) <=0 )