Shanghai Tengke Education Dream database training dry goods sharing domestic database DM6 first experience (2)

Let's experience it, create a vertical partition table:

create table test_part(
id int ,
t1 varchar(10),
t2 varchar(10),
t3 varchar(10),
t4 varchar(10),
CLUSTER PRIMARY KEY(id)
)
partition by column
((id,t1,t2),
(id,t3,t4)
);

  View the current partition table information through the DM system table sysparttables:

SQL>select * from sysparttables;
BASE_TABLE_ID        PART_TABLE_ID        RESVD1        RESVD2        RESVD3        RESVD4        RESVD5        
1    1007        1008        NULL    NULL    NULL    NULL    NULL    
2    1007        1009        NULL    NULL    NULL    NULL    NULL    
2 rows got
time used: 0.268(ms).

  We can see that the base table ID is 1007, and the partition subtable IDs are 1008 and 1009. Then we find the three tables 1007, 1008, and 1009.

SQL>select name from systables where id=1007;
name    
1    test_part    
1 rows got
time used: 0.301(ms).
SQL>select name from systables where id=1008;
name        
1    test_part00DMPART    
1 rows got
time used: 0.236(ms).
SQL>select name from systables where id=1009;
name        
1    test_part01DMPART    
1 rows got
time used: 0.185(ms).

  We use the tabledef function to verify the definition of these three tables.

SQL>select tabledef('mytest','sysdba','test_part');
1    CREATE TABLE "test_part" AT "mytest"
(
"id" INTEGER,
"t1" VARCHAR(10),
"t2" VARCHAR(10),
"t3" VARCHAR(10),
"t4" VARCHAR(10),
CLUSTER PRIMARY KEY("id"))PARTITION BY COLUMN(("id", "t1", "t2"), ("id", "t3", "t4"))
1 rows got
time used: 0.228(ms).

SQL>select tabledef('mytest','sysdba','test_part00DMPART');
1    CREATE TABLE "test_part00DMPART" AT "mytest"
(
"id" INTEGER,
"t1" VARCHAR(10),
"t2" VARCHAR(10),
CLUSTER PRIMARY KEY("id"))    
1 rows got
time used: 0.290(ms).

SQL>select tabledef('mytest','sysdba','test_part01DMPART');
1    CREATE TABLE "test_part01DMPART" AT "mytest"
(
"id" INTEGER,
"t3" VARCHAR(10),
"t4" VARCHAR(10),
CLUSTER PRIMARY KEY("id"))    
1 rows got
time used: 0.292(ms).

  You can see that the partition sub-tables automatically created by the system all contain the CLUSTER PK column id. The t1 and t2 columns are in the partition sub-table test_part00DMPART, and the t3 and t4 columns are in the partition sub-table test_part01DMPART.

SQL>explain select * from test_part;
#RSET:[2, 2, 0];
    #XNLP:[0, 0, 0]; CROSS_JOIN
        #CSEK:[2, 2, 0]; INDEX33555488(test_part00DMPART), FULL_SCAN
        #CSEK:[2, 2, 0]; INDEX33555489(test_part01DMPART), INDEX_EQU_SEARCH
time used: 7.339(ms).
SQL>explain select t1,t2 from test_part;
#RSET:[2, 2, 0];
    #CSEK:[2, 2, 0]; INDEX33555488(test_part00DMPART), FULL_SCAN
time used: 0.212(ms).
SQL>explain select t3,t4 from test_part;
#RSET:[2, 2, 0];
    #CSEK:[2, 2, 0]; INDEX33555489(test_part01DMPART), FULL_SCAN
time used: 0.199(ms).

  It can be clearly seen from the execution plan that when the full table is queried, the results are actually obtained by JOINing the two subtables. When only querying all the columns of the sub-table, only the sub-table is required. In actual applications, in situations similar to the above example, using vertical partitioning will greatly reduce the amount of query data, improve query efficiency, and optimize system performance.

Guess you like

Origin blog.csdn.net/qq_42726883/article/details/108651454