@@ -1796,16 +1796,15 @@ bool BTR_make_bounds(thread_db* tdbb, const IndexRetrieval* retrieval,
17961796 (retrieval->irb_desc .idx_flags & idx_unique) ? INTL_KEY_UNIQUE :
17971797 INTL_KEY_SORT;
17981798
1799+ bool forceIncludeUpper = false , forceIncludeLower = false ;
1800+
17991801 if (const auto count = retrieval->irb_upper_count )
18001802 {
18011803 const auto values = iterator ? iterator->getUpperValues () :
18021804 retrieval->irb_value + retrieval->irb_desc .idx_count ;
18031805
1804- bool forceInclude = false ;
18051806 errorCode = BTR_make_key (tdbb, count, values, retrieval->irb_scale ,
1806- idx, upper, keyType, &forceInclude);
1807- if (forceInclude)
1808- forceInclFlag |= irb_force_upper;
1807+ idx, upper, keyType, &forceIncludeUpper);
18091808 }
18101809
18111810 if (errorCode == idx_e_ok)
@@ -1815,11 +1814,8 @@ bool BTR_make_bounds(thread_db* tdbb, const IndexRetrieval* retrieval,
18151814 const auto values = iterator ? iterator->getLowerValues () :
18161815 retrieval->irb_value ;
18171816
1818- bool forceInclude = false ;
18191817 errorCode = BTR_make_key (tdbb, count, values, retrieval->irb_scale ,
1820- idx, lower, keyType, &forceInclude);
1821- if (forceInclude)
1822- forceInclFlag |= irb_force_lower;
1818+ idx, lower, keyType, &forceIncludeLower);
18231819 }
18241820 }
18251821
@@ -1829,6 +1825,22 @@ bool BTR_make_bounds(thread_db* tdbb, const IndexRetrieval* retrieval,
18291825 IndexErrorContext context (retrieval->irb_relation , &temp_idx);
18301826 context.raise (tdbb, errorCode);
18311827 }
1828+
1829+ // If retrieval is flagged to ignore NULLs and any segment of the key
1830+ // to be matched contains NULL, don't bother with a scan
1831+
1832+ if ((retrieval->irb_generic & irb_ignore_null_value_key) &&
1833+ ((retrieval->irb_upper_count && upper->key_nulls ) ||
1834+ (retrieval->irb_lower_count && lower->key_nulls )))
1835+ {
1836+ return false ;
1837+ }
1838+
1839+ if (forceIncludeUpper)
1840+ forceInclFlag |= irb_force_upper;
1841+
1842+ if (forceIncludeLower)
1843+ forceInclFlag |= irb_force_lower;
18321844 }
18331845
18341846 return true ;
0 commit comments