Tables are created in tablespaces, tablespaces are created in database partition groups (or sets of nodes, which you can create as you want) in Db2 for LUW.
You may use the following query to understand which tablespaces reside in which database partition groups.
SELECT
-- T.TBSPACEID, T.TBSPACETYPE
CASE T.DATATYPE
WHEN 'A' THEN 'REGULAR'
WHEN 'L' THEN 'LARGE'
WHEN 'T' THEN 'SYSTEMP'
WHEN 'U' THEN 'USRTEMP'
END DATATYPE
, T.DBPGNAME
--, T.PAGESIZE
, T.TBSPACE
--, B.BPNAME
--, G.MIN_NODENUM, G.MAX_NODENUM, G.NODE_COUNT
, G.NODES_LIST
FROM SYSCAT.TABLESPACES T
JOIN SYSCAT.BUFFERPOOLS B ON B.BUFFERPOOLID=T.BUFFERPOOLID
LEFT JOIN (
SELECT
DBPGNAME
, COUNT(*) NODE_COUNT
, MIN(DBPARTITIONNUM) MIN_NODENUM
, MAX(DBPARTITIONNUM) MAX_NODENUM
, LISTAGG(DBPARTITIONNUM, ',') WITHIN GROUP (ORDER BY DBPARTITIONNUM) NODES_LIST
FROM SYSCAT.DBPARTITIONGROUPDEF
GROUP BY DBPGNAME
) G ON G.DBPGNAME=T.DBPGNAME
ORDER BY T.TBSPACEID;
Let's say you get the following result:
DATATYPE DBPGNAME TBSPACE NODES_LIST
-------- --------------- ---------- ----------
...
LARGE IBMDEFAULTGROUP USERSPACE1 0,1,2,3
...
This means that if you run the following statement, then the table is created in a tablespace USERSPACE1
which resides on database partitions (nodes) 0-3, and table data is distributed between these nodes based on a hash value computed on values of YEAR
column.
CREATE TABLE SALES
(
CUSTOMER VARCHAR(80)
, REGION CHAR(5)
, YEAR INTEGER
)
IN USERSPACE1
DISTRIBUTE BY HASH (YEAR);
It's always advisable to specify a tablespase explicitly, unless the rules of choosing such a tablespace which Db2 uses in case of absence of such a specification are applicable for your particular statement.