Returns the database partition number and the database partition server number based on the distribution key values. An application can use this information to determine on which database partition server a specific row of a table is stored.
The partitioning data structure, db2RowPartNumStruct, is the input for this API. The information that is part of the input structure (partinfo) can be returned by the db2GetDistMap API. Another input is the character representations of the corresponding distribution key values. The output is a database partition number generated by the distribution strategy and the corresponding database partition server number from the distribution map. If the distribution map information is not provided, only the database partition number is returned. This can be useful when analyzing data distribution.
The database manager does not need to be running when this API is called.
This API must be invoked from a database partition server in the db2nodes.cfg file. This API should not be invoked from a client, since it could result in erroneous database partitioning information being returned due to differences in codepage and endianess between the client and the server.
None
db2ApiDf.h
db2GetRowPartNum (
sqluint32 db2VersionNumber, /* Database version number */
void * pParmStruct, /* In/out parameters */
struct sqlca * pSqlca); /* SQLCA */
where
SQL_STRUCTURE db2RowPartNumStruct
{
unsigned short num_ptrs; /* Number of pointers */
unsigned char **ptr_array; /* An array of pointers */
/* to char string */
unsigned short *ptr_lens; /* An array of character */
/* string lengths */
unsigned short countrycode; /* Territory/Country */
/* code */
unsigned short codepage; /* Code page */
struct db2PartitioningInfo *partinfo; /* Partitioning */
/* Information */
short *part_num; /* Partition number */
SQL_PDB_NODE_TYPE *node_num; /* Node number */
unsigned short chklvl; /* Check level */
short dataFormat; /* Data format */
};
SQL_STRUCTURE db2PartitioningInfo
{
sqluint32 pmaplen; /* Length of partitioning */
/* map */
SQL_PDB_NODE_TYPE *pmap; /* Partitioning map */
unsigned short sqld; /* # of used */
/* db2PartitioningKey */
/* elements */
struct db2PartitioningKey sqlpartkey[SQL_MAX_NUM_PART_KEYS]; /* */
/* KEYS */
};
SQL_STRUCTURE db2PartitioningKey
{
unsigned short sqltype; /* Date Type of Key */
unsigned short sqllen; /* Data Length of Key */
};
For numeric and datetime data types, the character representations must be at the code page of the respective system where the API is invoked.
If node_num is not null, the distribution map must be supplied; that is, pmaplen field in partinfo parameter (partinfo->pmaplen) is either 2 or 65536. Otherwise, SQLCODE -2032 is returned. The distribution key must be defined; that is, sqld field in partinfo parameter (partinfo->sqld) must be greater than zero. Otherwise, SQLCODE -2032 is returned.
If a null value is assigned to a non-nullable partitioning column, SQLCODE -6039 is returned.
All the leading blanks and trailing blanks of the input character string are stripped, except for the CHAR, VARCHAR, GRAPHIC, and VARGRAPHIC data types, where only trailing blanks are stripped.
The pmap in db2PartitioningInfo structure must point to an array of SQL_PDB_MAP_SIZE_32K entries.