Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf0a0c17

Browse files
committed
Refactor get_partition_for_tuple a bit.
Pending patches for both default partitioning and hash partitioningfind the current coding pattern to be inconvenient. Change it so thatwe switch on the partitioning method first and then do whatever isneeded.Amul Sul, reviewed by Jeevan Ladhe, with a few adjustments by me.Discussion:http://postgr.es/m/CAAJ_b97mTb=dG2pv6+1ougxEVZFVnZJajW+0QHj46mEE7WsoOQ@mail.gmail.comDiscussion:http://postgr.es/m/CAOgcT0M37CAztEinpvjJc18EdHfm23fw0EG9-36Ya=+rEFUqaQ@mail.gmail.com
1 parent3ca930f commitf0a0c17

File tree

1 file changed

+52
-48
lines changed

1 file changed

+52
-48
lines changed

‎src/backend/catalog/partition.c

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,10 +1920,7 @@ get_partition_for_tuple(PartitionDispatch *pd,
19201920
PartitionDispatchparent;
19211921
Datumvalues[PARTITION_MAX_KEYS];
19221922
boolisnull[PARTITION_MAX_KEYS];
1923-
intcur_offset,
1924-
cur_index;
1925-
inti,
1926-
result;
1923+
intresult;
19271924
ExprContext*ecxt=GetPerTupleExprContext(estate);
19281925
TupleTableSlot*ecxt_scantuple_old=ecxt->ecxt_scantuple;
19291926

@@ -1935,6 +1932,7 @@ get_partition_for_tuple(PartitionDispatch *pd,
19351932
PartitionDescpartdesc=parent->partdesc;
19361933
TupleTableSlot*myslot=parent->tupslot;
19371934
TupleConversionMap*map=parent->tupmap;
1935+
intcur_index=-1;
19381936

19391937
if (myslot!=NULL&&map!=NULL)
19401938
{
@@ -1966,61 +1964,67 @@ get_partition_for_tuple(PartitionDispatch *pd,
19661964
ecxt->ecxt_scantuple=slot;
19671965
FormPartitionKeyDatum(parent,slot,estate,values,isnull);
19681966

1969-
if (key->strategy==PARTITION_STRATEGY_RANGE)
1967+
/* Route as appropriate based on partitioning strategy. */
1968+
switch (key->strategy)
19701969
{
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+
casePARTITION_STRATEGY_LIST:
1971+
1972+
if (isnull[0])
19781973
{
1979-
*failed_at=parent;
1980-
*failed_slot=slot;
1981-
result=-1;
1982-
gotoerror_exit;
1974+
if (partition_bound_accepts_nulls(partdesc->boundinfo))
1975+
cur_index=partdesc->boundinfo->null_index;
19831976
}
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-
elseif (!isnull[0])
1995-
{
1996-
/* Else bsearch in partdesc->boundinfo */
1997-
boolequal= false;
1998-
1999-
cur_offset=partition_bound_bsearch(key,partdesc->boundinfo,
2000-
values, false,&equal);
2001-
switch (key->strategy)
2002-
{
2003-
casePARTITION_STRATEGY_LIST:
1977+
else
1978+
{
1979+
boolequal= false;
1980+
intcur_offset;
1981+
1982+
cur_offset=partition_bound_bsearch(key,
1983+
partdesc->boundinfo,
1984+
values,
1985+
false,
1986+
&equal);
20041987
if (cur_offset >=0&&equal)
20051988
cur_index=partdesc->boundinfo->indexes[cur_offset];
2006-
else
2007-
cur_index=-1;
2008-
break;
1989+
}
1990+
break;
1991+
1992+
casePARTITION_STRATEGY_RANGE:
1993+
{
1994+
boolequal= false;
1995+
intcur_offset;
1996+
inti;
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+
gotoerror_exit;
2007+
}
2008+
}
20092009

2010-
casePARTITION_STRATEGY_RANGE:
2010+
cur_offset=partition_bound_bsearch(key,
2011+
partdesc->boundinfo,
2012+
values,
2013+
false,
2014+
&equal);
20112015

20122016
/*
2013-
*Offsetreturned is such that the bound atoffset is
2014-
*found to beless or equalwith the tuple. So, the bound
2015-
* at offset+1would be the upper bound.
2017+
*The offsetreturned is such that the bound atcur_offset
2018+
*islessthanor equalto the tuple value, so the bound
2019+
* at offset+1is the upper bound.
20162020
*/
20172021
cur_index=partdesc->boundinfo->indexes[cur_offset+1];
2018-
break;
2022+
}
2023+
break;
20192024

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);
20242028
}
20252029

20262030
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp