- Notifications
You must be signed in to change notification settings - Fork 849
/
Copy pathexample.lst
266 lines (212 loc) · 9.52 KB
/
example.lst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
SQL> @example
SQL> -- ===================================================================================
SQL> -- Complete example of a partition exchange load using incremental stats
SQL> -- and a subpartitioned main table.
SQL> -- ===================================================================================
SQL> set linesize 2000
SQL> set trims on
SQL> set pagesize 50
SQL> set echo on
SQL>
SQL> drop table range_list_main_tab;
Table dropped.
SQL> drop table list_part_load_tab;
Table dropped.
SQL>
SQL> --
SQL> -- interval range-list table
SQL> --
SQL> create table range_list_main_tab
2 (num number,
3 ten number)
4 partition by range (num)
5 interval (1000)
6 subpartition by list (ten)
7 subpartition template
8 (subpartition t_spart1 values (0,2,4,6,8),
9 subpartition t_spart2 values (1,3,5,7,9))
10 (partition range_list_main_part1 values less than (1000),
11 partition range_list_main_part2 values less than (2000));
Table created.
SQL>
SQL> create index range_list_main_tab_n on range_list_main_tab(num) local;
Index created.
SQL>
SQL> --
SQL> -- list partitioned table
SQL> --
SQL> create table list_part_load_tab
2 (num number,
3 ten number)
4 partition by list (ten)
5 (partition list_part_load_part1 values (0,2,4,6,8),
6 partition list_part_load_part2 values (1,3,5,7,9));
Table created.
SQL>
SQL> exec dbms_stats.set_table_prefs(null, 'range_list_main_tab', 'incremental', 'true');
PL/SQL procedure successfully completed.
SQL> exec dbms_stats.set_table_prefs(null, 'list_part_load_tab', 'incremental', 'true');
PL/SQL procedure successfully completed.
SQL> exec dbms_stats.set_table_prefs(null, 'range_list_main_tab', 'incremental_level', 'partition');
PL/SQL procedure successfully completed.
SQL> exec dbms_stats.set_table_prefs(null, 'list_part_load_tab', 'incremental_level', 'table');
PL/SQL procedure successfully completed.
SQL>
SQL> --
SQL> -- The main table will have 998 rows
SQL> --
SQL> insert into range_list_main_tab
2 select rownum,mod(rownum,10)
3 from dual
4 connect by level<500
5 union all
6 select rownum+1000,mod(rownum,10)
7 from dual
8 connect by level<500;
998 rows created.
SQL>
SQL> --
SQL> -- The load table will have 999 rows
SQL> --
SQL> insert into list_part_load_tab
2 select rownum,mod(rownum,10)
3 from dual
4 connect by level<1000;
999 rows created.
SQL>
SQL> exec dbms_stats.gather_table_stats(null, 'range_list_main_tab');
PL/SQL procedure successfully completed.
SQL>
SQL> --
SQL> -- Let's sleep here to give the main table and load table
SQL> -- different last_analyzed times
SQL> --
SQL> host sleep 5
SQL>
SQL> exec dbms_stats.gather_table_stats(null, 'list_part_load_tab');
PL/SQL procedure successfully completed.
SQL>
SQL> --
SQL> -- Should be 1000 rows
SQL> --
SQL> select count(*) from range_list_main_tab;
COUNT(*)
----------
998
SQL>
SQL> select to_char(last_analyzed,'dd-mon-yyyy hh24:mi:ss') table_ana
2 from user_tables
3 where table_name = upper('range_list_main_tab');
TABLE_ANA
--------------------
16-dec-2016 07:53:44
SQL>
SQL> select partition_name, to_char(last_analyzed,'dd-mon-yyyy hh24:mi:ss') part_ana
2 from user_tab_partitions
3 where table_name = upper('range_list_main_tab')
4 order by partition_position;
PARTITION_NAME PART_ANA
-------------------------------------------------------------------------------------------------------------------------------- --------------------
RANGE_LIST_MAIN_PART1 16-dec-2016 07:53:44
RANGE_LIST_MAIN_PART2 16-dec-2016 07:53:44
SQL>
SQL> select subpartition_name, to_char(last_analyzed,'dd-mon-yyyy hh24:mi:ss') subpart_ana
2 from user_tab_subpartitions
3 where table_name = upper('range_list_main_tab')
4 order by subpartition_name;
SUBPARTITION_NAME SUBPART_ANA
-------------------------------------------------------------------------------------------------------------------------------- --------------------
RANGE_LIST_MAIN_PART1_T_SPART1 16-dec-2016 07:53:44
RANGE_LIST_MAIN_PART1_T_SPART2 16-dec-2016 07:53:44
RANGE_LIST_MAIN_PART2_T_SPART1 16-dec-2016 07:53:44
RANGE_LIST_MAIN_PART2_T_SPART2 16-dec-2016 07:53:44
SQL>
SQL> select to_char(last_analyzed,'dd-mon-yyyy hh24:mi:ss') load_table_ana
2 from user_tables
3 where table_name = upper('list_part_load_tab');
LOAD_TABLE_ANA
--------------------
16-dec-2016 07:53:50
SQL>
SQL> select partition_name, to_char(last_analyzed,'dd-mon-yyyy hh24:mi:ss') load_part_ana
2 from user_tab_partitions
3 where table_name = upper('list_part_load_tab')
4 order by partition_position;
PARTITION_NAME LOAD_PART_ANA
-------------------------------------------------------------------------------------------------------------------------------- --------------------
LIST_PART_LOAD_PART1 16-dec-2016 07:53:50
LIST_PART_LOAD_PART2 16-dec-2016 07:53:50
SQL>
SQL>
SQL> --
SQL> -- Perform the exchange after a delay
SQL> --
SQL> host sleep 5
SQL> alter table range_list_main_tab
2 exchange partition range_list_main_part1
3 with table list_part_load_tab;
Table altered.
SQL>
SQL> --
SQL> -- Exchange complete at:
SQL> --
SQL> select to_char(sysdate,'dd-mon-yyyy hh24:mi:ss') exchange_complete
2 from dual;
EXCHANGE_COMPLETE
--------------------
16-dec-2016 07:53:55
SQL>
SQL> exec dbms_stats.gather_table_stats(null, 'range_list_main_tab');
PL/SQL procedure successfully completed.
SQL>
SQL> --
SQL> -- Should now be 1498 rows
SQL> --
SQL> select count(*) from range_list_main_tab;
COUNT(*)
----------
1498
SQL>
SQL> --
SQL> -- The time shown here will be the most recent because the global
SQL> -- statistics must be updated after the partition has been exchanged.
SQL> -- So, expect the time to be similar to the completion exchange time.
SQL> --
SQL> select to_char(last_analyzed,'dd-mon-yyyy hh24:mi:ss') table_ana
2 from user_tables
3 where table_name = upper('range_list_main_tab');
TABLE_ANA
--------------------
16-dec-2016 07:53:55
SQL>
SQL> --
SQL> -- Part 1 statistics were gathered earlier, because they came from the load
SQL> -- table. They did not have to be regathered after the partition was echanged.
SQL> -- Part 2 statistics have not been regathered - there is no need.
SQL> --
SQL> select partition_name, to_char(last_analyzed,'dd-mon-yyyy hh24:mi:ss') part_ana
2 from user_tab_partitions
3 where table_name = upper('range_list_main_tab')
4 order by partition_position;
PARTITION_NAME PART_ANA
-------------------------------------------------------------------------------------------------------------------------------- --------------------
RANGE_LIST_MAIN_PART1 16-dec-2016 07:53:50
RANGE_LIST_MAIN_PART2 16-dec-2016 07:53:44
SQL>
SQL> --
SQL> -- The Part 1 subpartition stats came from the load table so they have not
SQL> -- been regathered after the exchange.
SQL> -- Part 2 subpartition stats have not been regathered - there is no need.
SQL> --
SQL> select subpartition_name, to_char(last_analyzed,'dd-mon-yyyy hh24:mi:ss') subpart_ana
2 from user_tab_subpartitions
3 where table_name = upper('range_list_main_tab')
4 order by subpartition_name;
SUBPARTITION_NAME SUBPART_ANA
-------------------------------------------------------------------------------------------------------------------------------- --------------------
RANGE_LIST_MAIN_PART1_T_SPART1 16-dec-2016 07:53:50
RANGE_LIST_MAIN_PART1_T_SPART2 16-dec-2016 07:53:50
RANGE_LIST_MAIN_PART2_T_SPART1 16-dec-2016 07:53:44
RANGE_LIST_MAIN_PART2_T_SPART2 16-dec-2016 07:53:44
SQL>
SQL> spool off