SQL>ALTER SESSION SET NLS_DATE_FORMAT ='YYYY-MM-DD HH24:MI:SS';
Session altered.
创建分区表
1 2 3 4 5 6 7 8 9 10 11 12 13
SQL>CREATETABLE TEST_PARTITION2 ( id NUMBER, name VARCHAR2(50), register_date DATE ) PARTITIONBYRANGE (register_date) ( PARTITION p_2019 VALUES LESS THAN (TO_DATE('01-01-2020', 'dd-mm-yyyy')), PARTITION p_2020 VALUES LESS THAN (TO_DATE('01-01-2021', 'dd-mm-yyyy')), PARTITION p_2021 VALUES LESS THAN (TO_DATE('01-01-2022', 'dd-mm-yyyy')) ); Table created.
SQL>SELECT'p_2019'as parted, COUNT(*) FROM TEST_PARTITION2 PARTITION(p_2019) UNIONALL SELECT'p_2020'as parted, COUNT(*) FROM TEST_PARTITION2 PARTITION(p_2020) UNIONALL SELECT'p_2021'as parted, COUNT(*) FROM TEST_PARTITION2 PARTITION(p_2021); PARTED COUNT(*) ------------ ---------- p_2019 100000 p_2020 100000 p_2021 100000
搜集统计信息并查看
1 2 3 4 5 6 7 8 9 10 11 12 13 14
SQL>EXEC DBMS_STATS.GATHER_TABLE_STATS('SYS','TEST_PARTITION2',estimate_percent=>100,method_opt=>'FOR ALL COLUMNS SIZE AUTO',cascade=>TRUE);
PL/SQLprocedure successfully completed.
SQL>set lines 200 col PARTITION_NAME for a40 select partition_name,object_type,num_rows,to_char(last_analyzed,'yyyy-mm-dd hh24:mi:ss') last_analyzed from dba_tab_statistics where table_name=upper('TEST_PARTITION2');SQL>SQL>
SQL>SELECT'p_2019'as parted, COUNT(*) FROM TEST_PARTITION2 PARTITION(p_2019) UNIONALL SELECT'p_2020'as parted, COUNT(*) FROM TEST_PARTITION2 PARTITION(p_2020) UNIONALL SELECT'p_2021'as parted, COUNT(*) FROM TEST_PARTITION2 PARTITION(p_2021); PARTED COUNT(*) ------------ ---------- p_2019 116000 p_2020 106000 p_2021 100000 SQL>set lines 200 col PARTITION_NAME for a20 select partition_name,object_type,num_rows,to_char(last_analyzed,'yyyy-mm-dd hh24:mi:ss') last_analyzed from dba_tab_statistics where table_name=upper('TEST_PARTITION2');SQL>SQL> PARTITION_NAME OBJECT_TYPE NUM_ROWS LAST_ANALYZED ---------------- ------------------------ ---------- --------------- TABLE3000002023-08-0411:49:28 P_2019 PARTITION1000002023-08-0411:49:27 P_2020 PARTITION1000002023-08-0411:49:28 P_2021 PARTITION1000002023-08-0411:49:28
调整自动统计信息的任务运行时间为12:10
1 2 3 4 5 6 7
BEGIN DBMS_SCHEDULER.SET_ATTRIBUTE( name =>'"SYS"."THURSDAY_WINDOW"', attribute =>'REPEAT_INTERVAL', VALUE=>'freq=daily;byday=THU;byhour=12;byminute=10; bysecond=0'); END; /
等自动统计信息的任务执行之后,检查统计信息如下
1 2 3 4 5 6 7 8 9 10 11
SQL>set lines 200 col PARTITION_NAME for a20 select partition_name,object_type,num_rows,to_char(last_analyzed,'yyyy-mm-dd hh24:mi:ss') last_analyzed from dba_tab_statistics where table_name=upper('TEST_PARTITION2');SQL>SQL> PARTITION_NAME OBJECT_TYPE NUM_ROWS LAST_ANALYZED ------------- --------------- ---------- ---------------------- TABLE3000002023-08-0411:49:28 P_2019 PARTITION1160002023-08-0412:10:38 P_2020 PARTITION1000002023-08-0411:49:28 P_2021 PARTITION1000002023-08-0411:49:28