关于物化视图实验几个证明
在工作中涉及物化视图使用,存在一些疑问,通过实验证明了一下
1.对于 ON PREBUILT TABLE 方式建立的物化视图,如果DROP MATERIALIZED VIEW后,原表是否会保留下来。答案:会
2.对于物化视图组,使用DBMS_REFRESH.DESTROY后,job是否会删除? 答案:会
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 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | PROMPT 1.对于 ON PREBUILT TABLE 方式建立的物化视图,如果 DROP MATERIALIZED VIEW 后,原表是否会保留下来。 SQL> CREATE TABLE t_test AS SELECT * FROM dba_objects WHERE object_id IS NOT NULL ; Table created SQL> alter table T_TEST 2 add constraint pk_id primary key (OBJECT_ID); Table altered SQL> SQL> CREATE TABLE mv_test AS SELECT * FROM t_test; Table created SQL> SQL> alter table MV_TEST 2 add constraint pk_mv_id primary key (OBJECT_ID); Table altered SQL> CREATE MATERIALIZED VIEW LOG ON t_test; Materialized view log created SQL> SQL> CREATE MATERIALIZED VIEW mv_test 2 ON PREBUILT TABLE USING INDEX 3 REFRESH FORCE ON DEMAND 4 WITH PRIMARY KEY 5 AS 6 SELECT * FROM t_test; Materialized view created SQL> CREATE MATERIALIZED VIEW LOG ON mv_test WITH ROWID, SEQUENCE ; Materialized view log created SQL> select * from mlog$_t_test; OBJECT_ID SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ ---------- ----------- --------- --------- -------------------------------------------------------------------------------- SQL> select * from mlog$_mv_test; M_ROW$$ SEQUENCE $$ SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ -------------------------------------------------------------------------------- ---------- ----------- --------- --------- -------------------------------------------------------------------------------- SQL> insert into t_test (object_id,object_name) values (307454, 'T_TEST1' ); 1 row inserted SQL> COMMIT ; Commit complete SQL> select * from mlog$_t_test; OBJECT_ID SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ ---------- ----------- --------- --------- -------------------------------------------------------------------------------- 307454 4000-1-1 I N FEFF SQL> select * from mlog$_mv_test; M_ROW$$ SEQUENCE $$ SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ -------------------------------------------------------------------------------- ---------- ----------- --------- --------- -------------------------------------------------------------------------------- SQL> DROP MATERIALIZED VIEW mv_test; Materialized view dropped SQL> select count (*) from mv_test; SQL> COUNT (*) ---------- 81436 -- 表mv_test还是会保存的 SQL> select * from mlog$_t_test; OBJECT_ID SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ ---------- ----------- --------- --------- -------------------------------------------------------------------------------- -- 物化视图删除后,物化视图日志增量数据被删除了 SQL> select * from mlog$_mv_test; M_ROW$$ SEQUENCE $$ SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ -------------------------------------------------------------------------------- ---------- ----------- --------- --------- -------------------------------------------------------------------------------- SQL> insert into t_test (object_id,object_name) values (307455, 'T_TEST1' ); 1 row inserted SQL> commit ; Commit complete SQL> select * from mlog$_t_test; OBJECT_ID SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ ---------- ----------- --------- --------- -------------------------------------------------------------------------------- 307455 4000-1-1 I N FEFF SQL> select * from mlog$_mv_test; M_ROW$$ SEQUENCE $$ SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ -------------------------------------------------------------------------------- ---------- ----------- --------- --------- -------------------------------------------------------------------------------- SQL> SQL> CREATE MATERIALIZED VIEW mv_test 2 ON PREBUILT TABLE USING INDEX 3 REFRESH FORCE ON DEMAND 4 WITH PRIMARY KEY 5 AS 6 SELECT * FROM t_test; Materialized view created SQL> select * from mlog$_t_test; OBJECT_ID SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ ---------- ----------- --------- --------- -------------------------------------------------------------------------------- -- 物化视图创建后后,物化视图日志增量数据会被删除了 SQL> select * from mlog$_mv_test; M_ROW$$ SEQUENCE $$ SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ -------------------------------------------------------------------------------- ---------- ----------- --------- --------- -------------------------------------------------------------------------------- SQL> insert into t_test (object_id,object_name) values (307456, 'T_TEST1' ); 1 row inserted SQL> commit ; Commit complete SQL> select * from mlog$_t_test; OBJECT_ID SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ ---------- ----------- --------- --------- -------------------------------------------------------------------------------- 307456 4000-1-1 I N FEFF SQL> select * from mlog$_mv_test; M_ROW$$ SEQUENCE $$ SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ -------------------------------------------------------------------------------- ---------- ----------- --------- --------- -------------------------------------------------------------------------------- SQL> EXEC DBMS_MVIEW.REFRESH( 'MV_TEST' , 'C' ); PL/SQL procedure successfully completed -- 全量刷新 SQL> select * from mlog$_t_test; OBJECT_ID SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ ---------- ----------- --------- --------- -------------------------------------------------------------------------------- SQL> select * from mlog$_mv_test; M_ROW$$ SEQUENCE $$ SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ -------------------------------------------------------------------------------- ---------- ----------- --------- --------- -------------------------------------------------------------------------------- SQL> select count (*) from t_test; COUNT (*) ---------- 81439 SQL> select count (*) from mv_test; COUNT (*) ---------- 81439 SQL> insert into t_test (object_id,object_name) values (307457, 'T_TEST1' ); 1 row inserted SQL> commit ; Commit complete SQL> select * from mlog$_t_test; OBJECT_ID SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ ---------- ----------- --------- --------- -------------------------------------------------------------------------------- 307457 4000-1-1 I N FEFF SQL> select * from mlog$_mv_test; M_ROW$$ SEQUENCE $$ SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ -------------------------------------------------------------------------------- ---------- ----------- --------- --------- -------------------------------------------------------------------------------- SQL> EXEC DBMS_MVIEW.REFRESH( 'MV_TEST' , 'F' ); -- 进行增量刷新 PL/SQL procedure successfully completed SQL> select * from mlog$_t_test; OBJECT_ID SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ ---------- ----------- --------- --------- -------------------------------------------------------------------------------- SQL> select * from mlog$_mv_test; M_ROW$$ SEQUENCE $$ SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ -------------------------------------------------------------------------------- ---------- ----------- --------- --------- -------------------------------------------------------------------------------- AABLD/AAZAABvT9AAU 1030001 4000-1-1 I N FEFF PROMPT 2.对于物化视图组,使用DBMS_REFRESH.DESTROY后,job是否会删除? SQL> CREATE TABLE t_test1 AS SELECT * FROM dba_objects WHERE object_id IS NOT NULL ; Table created SQL> CREATE TABLE t_test2 AS SELECT * FROM dba_objects WHERE object_id IS NOT NULL ; Table created SQL> CREATE TABLE t_test3 AS SELECT * FROM dba_objects WHERE object_id IS NOT NULL ; Table created SQL> SQL> CREATE MATERIALIZED VIEW mv_test1 2 BUILD IMMEDIATE 3 REFRESH FORCE ON DEMAND 4 WITH rowid 5 AS 6 SELECT * FROM t_test1; Materialized view created SQL> drop MATERIALIZED VIEW mv_test1; Materialized view dropped SQL> SQL> DROP TABLE t_test1; Table dropped SQL> DROP TABLE t_test2; Table dropped SQL> DROP TABLE t_test3; Table dropped SQL> SQL> CREATE TABLE t_test1 AS SELECT * FROM dba_objects WHERE object_id IS NOT NULL ; Table created SQL> CREATE TABLE t_test2 AS SELECT * FROM dba_objects WHERE object_id IS NOT NULL ; Table created SQL> CREATE TABLE t_test3 AS SELECT * FROM dba_objects WHERE object_id IS NOT NULL ; Table created SQL> SQL> CREATE MATERIALIZED VIEW LOG ON t_test1 WITH ROWID, SEQUENCE ; Materialized view log created SQL> CREATE MATERIALIZED VIEW LOG ON t_test2 WITH ROWID, SEQUENCE ; Materialized view log created SQL> CREATE MATERIALIZED VIEW LOG ON t_test3 WITH ROWID, SEQUENCE ; Materialized view log created SQL> SQL> CREATE MATERIALIZED VIEW mv_test1 2 BUILD IMMEDIATE 3 REFRESH FORCE ON DEMAND 4 WITH rowid 5 AS 6 SELECT * FROM t_test1; Materialized view created SQL> CREATE MATERIALIZED VIEW mv_test2 2 BUILD IMMEDIATE 3 REFRESH FORCE ON DEMAND 4 WITH rowid 5 AS 6 SELECT * FROM t_test2; Materialized view created SQL> CREATE MATERIALIZED VIEW mv_test3 2 BUILD IMMEDIATE 3 REFRESH FORCE ON DEMAND 4 WITH rowid 5 AS 6 SELECT * FROM t_test3; Materialized view created SQL> SQL> insert into t_test (object_id,object_name) values (307458, 'T_TEST1' ); 1 row inserted SQL> insert into t_test1 (object_id,object_name) values (307458, 'T_TEST1' ); 1 row inserted SQL> insert into t_test2 (object_id,object_name) values (307458, 'T_TEST1' ); 1 row inserted SQL> insert into t_test3 (object_id,object_name) values (307458, 'T_TEST1' ); 1 row inserted SQL> commit ; Commit complete SQL> SQL> select * from mlog$_t_test; OBJECT_ID SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ ---------- ----------- --------- --------- -------------------------------------------------------------------------------- 307458 4000-1-1 I N FEFF SQL> select * from mlog$_t_test1; M_ROW$$ SEQUENCE $$ SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ -------------------------------------------------------------------------------- ---------- ----------- --------- --------- -------------------------------------------------------------------------------- AABLEMAAuAAA6u2AAA 1040001 4000-1-1 I N FEFF SQL> select * from mlog$_t_test2; M_ROW$$ SEQUENCE $$ SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ -------------------------------------------------------------------------------- ---------- ----------- --------- --------- -------------------------------------------------------------------------------- AABLENAAvAAACC2AAA 1040002 4000-1-1 I N FEFF SQL> select * from mlog$_t_test3; M_ROW$$ SEQUENCE $$ SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ -------------------------------------------------------------------------------- ---------- ----------- --------- --------- -------------------------------------------------------------------------------- AABLEOAAuAAA7C2AAA 1040003 4000-1-1 I N FEFF SQL> SQL> EXEC DBMS_MVIEW.REFRESH( 'MV_TEST' , 'F' ); PL/SQL procedure successfully completed SQL> EXEC DBMS_MVIEW.REFRESH( 'MV_TEST1' , 'F' ); PL/SQL procedure successfully completed SQL> EXEC DBMS_MVIEW.REFRESH( 'MV_TEST2' , 'F' ); PL/SQL procedure successfully completed SQL> EXEC DBMS_MVIEW.REFRESH( 'MV_TEST3' , 'F' ); PL/SQL procedure successfully completed SQL> SQL> select * from mlog$_t_test; OBJECT_ID SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ ---------- ----------- --------- --------- -------------------------------------------------------------------------------- SQL> select * from mlog$_t_test1; M_ROW$$ SEQUENCE $$ SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ -------------------------------------------------------------------------------- ---------- ----------- --------- --------- -------------------------------------------------------------------------------- SQL> select * from mlog$_t_test2; M_ROW$$ SEQUENCE $$ SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ -------------------------------------------------------------------------------- ---------- ----------- --------- --------- -------------------------------------------------------------------------------- SQL> select * from mlog$_t_test3; M_ROW$$ SEQUENCE $$ SNAPTIME$$ DMLTYPE$$ OLD_NEW$$ CHANGE_VECTOR$$ -------------------------------------------------------------------------------- ---------- ----------- --------- --------- -------------------------------------------------------------------------------- SQL> EXEC DBMS_REFRESH.MAKE( 'REP_CENTREX' , 'MV_TEST,MV_TEST1,MV_TEST2,MV_TEST3' , TRUNC(SYSDATE+1)+2/24, 'trunc(sysdate+1)+2/24' ); PL/SQL procedure successfully completed SQL> EXEC DBMS_REFRESH.REFRESH( 'REP_CENTREX' ); PL/SQL procedure successfully completed SQL> select * from user_jobs; JOB LOG_USER PRIV_USER SCHEMA_USER LAST_DATE LAST_SEC THIS_DATE THIS_SEC NEXT_DATE NEXT_SEC TOTAL_TIME BROKEN INTERVAL FAILURES WHAT NLS_ENV MISC_ENV INSTANCE ---------- ------------------------------ ------------------------------ ------------------------------ ----------- ---------------- ----------- ---------------- ----------- ---------------- ---------- ------ -------------------------------------------------------------------------------- ---------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ---------------------------------------------------------------- ---------- 2321 DAVID DAVID DAVID 2012-12-22 02:00:00 0 N trunc(sysdate+1)+2/24 dbms_refresh.refresh( '"DAVID"."REP_CENTREX"' ); NLS_LANGUAGE= 'SIMPLIFIED CHINESE' NLS_TERRITORY= 'CHINA' NLS_CURRENCY= '¥' NLS_ISO 0102000200000000 0 -- 创建的REP_CENTREX的物化视图组定时刷新job SQL> EXEC DBMS_REFRESH.DESTROY( 'REP_CENTREX' ); PL/SQL procedure successfully completed SQL> select * from user_jobs; JOB LOG_USER PRIV_USER SCHEMA_USER LAST_DATE LAST_SEC THIS_DATE THIS_SEC NEXT_DATE NEXT_SEC TOTAL_TIME BROKEN INTERVAL FAILURES WHAT NLS_ENV MISC_ENV INSTANCE ---------- ------------------------------ ------------------------------ ------------------------------ ----------- ---------------- ----------- ---------------- ----------- ---------------- ---------- ------ -------------------------------------------------------------------------------- ---------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ---------------------------------------------------------------- ---------- -- job也同时删除了 |
posted on 2012-12-21 17:23 DJ IN MUSIC 阅读(361) 评论(0) 编辑 收藏 举报