@@ -1797,16 +1797,15 @@ bool BTR_make_bounds(thread_db* tdbb, const IndexRetrieval* retrieval,
17971797 (retrieval->irb_desc .idx_flags & idx_unique) ? INTL_KEY_UNIQUE :
17981798 INTL_KEY_SORT;
17991799
1800+ bool forceIncludeUpper = false , forceIncludeLower = false ;
1801+
18001802 if (const auto count = retrieval->irb_upper_count )
18011803 {
18021804 const auto values = iterator ? iterator->getUpperValues () :
18031805 retrieval->irb_value + retrieval->irb_desc .idx_count ;
18041806
1805- bool forceInclude = false ;
18061807 errorCode = BTR_make_key (tdbb, count, values, retrieval->irb_scale ,
1807- idx, upper, keyType, &forceInclude);
1808- if (forceInclude)
1809- forceInclFlag |= irb_force_upper;
1808+ idx, upper, keyType, &forceIncludeUpper);
18101809 }
18111810
18121811 if (errorCode == idx_e_ok)
@@ -1816,11 +1815,8 @@ bool BTR_make_bounds(thread_db* tdbb, const IndexRetrieval* retrieval,
18161815 const auto values = iterator ? iterator->getLowerValues () :
18171816 retrieval->irb_value ;
18181817
1819- bool forceInclude = false ;
18201818 errorCode = BTR_make_key (tdbb, count, values, retrieval->irb_scale ,
1821- idx, lower, keyType, &forceInclude);
1822- if (forceInclude)
1823- forceInclFlag |= irb_force_lower;
1819+ idx, lower, keyType, &forceIncludeLower);
18241820 }
18251821 }
18261822
@@ -1830,6 +1826,22 @@ bool BTR_make_bounds(thread_db* tdbb, const IndexRetrieval* retrieval,
18301826 IndexErrorContext context (retrieval->irb_relation , &temp_idx);
18311827 context.raise (tdbb, errorCode);
18321828 }
1829+
1830+ // If retrieval is flagged to ignore NULLs and any segment of the key
1831+ // to be matched contains NULL, don't bother with a scan
1832+
1833+ if ((retrieval->irb_generic & irb_ignore_null_value_key) &&
1834+ ((retrieval->irb_upper_count && upper->key_nulls ) ||
1835+ (retrieval->irb_lower_count && lower->key_nulls )))
1836+ {
1837+ return false ;
1838+ }
1839+
1840+ if (forceIncludeUpper)
1841+ forceInclFlag |= irb_force_upper;
1842+
1843+ if (forceIncludeLower)
1844+ forceInclFlag |= irb_force_lower;
18331845 }
18341846
18351847 return true ;
0 commit comments