There is a log-type table in a system. The current size is about 500 MB. The execution plan of statements related to the table is to scan the entire table. Below is the table
There is a log-type table in a system. The current size is about 500 MB. The execution plan of statements related to the table is to scan the entire table. Below is the table
There is a log-type table in a system. The current size is about 500 MB. The execution plan of statements related to the table is to scan the entire table.
The table definition is as follows:
01 create table p_siteaccesslog
02 (
03 logID varchar (40) not null,
04 infoType varchar (20) default 'SITE ',
05 siteId varchar (30 ),
06 columnId varchar (30 ),
07 infoId varchar (30 ),
08 url varchar (300 ),
09 location varchar (80 ),
10 action varchar (20 ),
11 accessDate varchar (10 ),
12 accessTime varchar (8 ),
13 sessionID varchar (90 ),
14 userName varchar (30 ),
15 userBrowser varchar (50 ),
16 userOS varchar (30 ),
17 userIp varchar (30 ),
18 localization varchar (100 ),
19 constraint PK_p_siteaccesslog primary key (logID)
20)
This table has a primary key, which is assigned a primary key for each log. It seems that this primary key will not be used for data query for one hundred years. So remove it from the new partition table.
1 test $ ora8i@4.20 SQL> l
2 1 * select segment_name, sum (bytes/1048576) MB from user_extents group by segment_name order by 2 desc
3 test $ ora8i@4.20 SQL>/
4
5 SEGMENT_NAME MB
6 --------------------------------------------------
7 P_SITEACCESSLOG 536
Because it is a log-type table, the first thought is to partition by time and eliminate (switch) old data.
As a result, a partition table is created based on the monthly partition policy:
01 create table my_p_siteaccesslog
02 (
03 logID varchar (40) not null,
04 infoType varchar (20) default 'SITE ',
05 siteId varchar (30 ),
06 columnId varchar (30 ),
07 infoId varchar (30 ),
08 url varchar (300 ),
09 location varchar (80 ),
10 action varchar (20 ),
11 accessDate varchar (10 ),
12 accessTime varchar (8 ),
13 sessionID varchar (90 ),
14 userName varchar (30 ),
15 userBrowser varchar (50 ),
16 userOS varchar (30 ),
17 userIp varchar (30 ),
18 localization varchar (100)
19)
20 partition by range (accessDate)
21 (
22 partition pbf2009 values less than ('2017-01-01 '),
23 partition p200901 values less than ('2017-02-01 '),
24 partition p200902 values less than ('2017-03-01 '),
25 partition p200903 values less than ('2017-04-01 '),
26 partition p200904 values less than ('2017-05-01 '),
27 partition p200905 values less than ('2017-06-01 '),
28 partition p200906 values less than ('2017-07-01 '),
29 partition p200907 values less than ('2017-08-01 '),
30 partition p200908 values less than ('2017-09-01 '),
31 partition p200909 values less than ('2017-10-01 '),
32 partition p200910 values less than ('2017-11-01 '),
33 partition p200911 values less than ('2017-12-01 '),
34 partition p200912 values less than ('2017-01-01 '),
35 partition p201001 values less than ('2017-02-01 '),
36 partition p201002 values less than ('2017-03-01 '),
37 partition p201003 values less than ('2017-04-01 '),
38 partition p201004 values less than ('2017-05-01 '),
39 partition p201005 values less than ('2017-06-01 '),
40 partition p201006 values less than ('2017-07-01 '),
41 partition p201007 values less than ('2017-08-01 '),
42 partition p201008 values less than ('2017-09-01 '),
43 partition p201009 values less than ('2017-10-01 '),
44 partition p201010 values less than ('2017-11-01 '),
45 partition p201011 values less than ('2017-12-01 '),
46 partition p201012 values less than ('2017-01-01 ')
47)