Materialized aggregate view index [message #558928] |
Wed, 27 June 2012 08:43 |
John Watson
Messages: 8960 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
When you create a MAV, you automatically get a hidden column and an index. Does anyone know what it is for? Can you think of a way to use it? Here's an example,drop user jon cascade;
grant dba to jon identified by jon;
conn jon/jon
create table emp as select * from scott.emp;
create materialized view mv1 enable query rewrite as
select deptno,sum(sal) from emp group by deptno;
select object_name,object_type from user_objects;
select index_name,column_name from user_ind_columns where table_name='MV1';
select column_name,hidden_column from user_tab_cols where table_name='MV1';
select deptno,"SUM(SAL)",sys_nc00003$ from mv1;
|
|
|
|
Re: Materialized aggregate view index [message #559048 is a reply to message #558939] |
Thu, 28 June 2012 04:27 |
John Watson
Messages: 8960 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Thank you for replying, I hope I'm beginning to understand what is going on.
The hidden and indexed column is a virtual column, defined in dba_tab_cols.data_default. The function that creates the virtual column is sys_op_map_nonnull, which is not documented, that converts nulls into a form that can be compared:
orcl> select * from dual where null=null;
no rows selected
orcl> select * from dual where sys_op_map_nonnull(null)=sys_op_map_nonnull(null);
D
-
X
orcl> The purpose of all this is to facilitate fast refresh from MV logs, in the case where the aggregating column is nullable. I can't imagine a circumstance where you would want to aggregate on a nullable column, but without this an index couldn't be used to locate the matching row.
I realize that questions of this nature are often of no immediate practical value, but I find that reverse engineering Oracle features is the best way to learn how to exploit them.
|
|
|