@@ -1920,10 +1920,7 @@ get_partition_for_tuple(PartitionDispatch *pd,
1920
1920
PartitionDispatch parent ;
1921
1921
Datum values [PARTITION_MAX_KEYS ];
1922
1922
bool isnull [PARTITION_MAX_KEYS ];
1923
- int cur_offset ,
1924
- cur_index ;
1925
- int i ,
1926
- result ;
1923
+ int result ;
1927
1924
ExprContext * ecxt = GetPerTupleExprContext (estate );
1928
1925
TupleTableSlot * ecxt_scantuple_old = ecxt -> ecxt_scantuple ;
1929
1926
@@ -1935,6 +1932,7 @@ get_partition_for_tuple(PartitionDispatch *pd,
1935
1932
PartitionDesc partdesc = parent -> partdesc ;
1936
1933
TupleTableSlot * myslot = parent -> tupslot ;
1937
1934
TupleConversionMap * map = parent -> tupmap ;
1935
+ int cur_index = -1 ;
1938
1936
1939
1937
if (myslot != NULL && map != NULL )
1940
1938
{
@@ -1966,61 +1964,67 @@ get_partition_for_tuple(PartitionDispatch *pd,
1966
1964
ecxt -> ecxt_scantuple = slot ;
1967
1965
FormPartitionKeyDatum (parent , slot , estate , values , isnull );
1968
1966
1969
- if (key -> strategy == PARTITION_STRATEGY_RANGE )
1967
+ /* Route as appropriate based on partitioning strategy. */
1968
+ switch (key -> strategy )
1970
1969
{
1971
- /*
1972
- * Since we cannot route tuples with NULL partition keys through a
1973
- * range-partitioned table, simply return that no partition exists
1974
- */
1975
- for (i = 0 ; i < key -> partnatts ; i ++ )
1976
- {
1977
- if (isnull [i ])
1970
+ case PARTITION_STRATEGY_LIST :
1971
+
1972
+ if (isnull [0 ])
1978
1973
{
1979
- * failed_at = parent ;
1980
- * failed_slot = slot ;
1981
- result = -1 ;
1982
- goto error_exit ;
1974
+ if (partition_bound_accepts_nulls (partdesc -> boundinfo ))
1975
+ cur_index = partdesc -> boundinfo -> null_index ;
1983
1976
}
1984
- }
1985
- }
1986
-
1987
- /*
1988
- * A null partition key is only acceptable if null-accepting list
1989
- * partition exists.
1990
- */
1991
- cur_index = -1 ;
1992
- if (isnull [0 ] && partition_bound_accepts_nulls (partdesc -> boundinfo ))
1993
- cur_index = partdesc -> boundinfo -> null_index ;
1994
- else if (!isnull [0 ])
1995
- {
1996
- /* Else bsearch in partdesc->boundinfo */
1997
- bool equal = false;
1998
-
1999
- cur_offset = partition_bound_bsearch (key , partdesc -> boundinfo ,
2000
- values , false, & equal );
2001
- switch (key -> strategy )
2002
- {
2003
- case PARTITION_STRATEGY_LIST :
1977
+ else
1978
+ {
1979
+ bool equal = false;
1980
+ int cur_offset ;
1981
+
1982
+ cur_offset = partition_bound_bsearch (key ,
1983
+ partdesc -> boundinfo ,
1984
+ values ,
1985
+ false,
1986
+ & equal );
2004
1987
if (cur_offset >= 0 && equal )
2005
1988
cur_index = partdesc -> boundinfo -> indexes [cur_offset ];
2006
- else
2007
- cur_index = -1 ;
2008
- break ;
1989
+ }
1990
+ break ;
1991
+
1992
+ case PARTITION_STRATEGY_RANGE :
1993
+ {
1994
+ bool equal = false;
1995
+ int cur_offset ;
1996
+ int i ;
1997
+
1998
+ /* No range includes NULL. */
1999
+ for (i = 0 ; i < key -> partnatts ; i ++ )
2000
+ {
2001
+ if (isnull [i ])
2002
+ {
2003
+ * failed_at = parent ;
2004
+ * failed_slot = slot ;
2005
+ result = -1 ;
2006
+ goto error_exit ;
2007
+ }
2008
+ }
2009
2009
2010
- case PARTITION_STRATEGY_RANGE :
2010
+ cur_offset = partition_bound_bsearch (key ,
2011
+ partdesc -> boundinfo ,
2012
+ values ,
2013
+ false,
2014
+ & equal );
2011
2015
2012
2016
/*
2013
- * Offset returned is such that the bound at offset is
2014
- * found to be less or equal with the tuple. So, the bound
2015
- * at offset+1 would be the upper bound.
2017
+ * The offset returned is such that the bound at cur_offset
2018
+ * is less than or equal to the tuple value, so the bound
2019
+ * at offset+1 is the upper bound.
2016
2020
*/
2017
2021
cur_index = partdesc -> boundinfo -> indexes [cur_offset + 1 ];
2018
- break ;
2022
+ }
2023
+ break ;
2019
2024
2020
- default :
2021
- elog (ERROR , "unexpected partition strategy: %d" ,
2022
- (int ) key -> strategy );
2023
- }
2025
+ default :
2026
+ elog (ERROR , "unexpected partition strategy: %d" ,
2027
+ (int ) key -> strategy );
2024
2028
}
2025
2029
2026
2030
/*
0 commit comments