Indexed views using indexes on base table
Hi all,
CREATE VIEW Sales.vOrders
WITH SCHEMABINDING
AS
SELECT SUM(UnitPrice*OrderQty*(1.00-UnitPriceDiscount)) AS Revenue,
OrderDate, ProductID, COUNT_BIG(*) AS COUNT
FROM Sales.SalesOrderDetail AS od, Sales.SalesOrderHeader AS o
WHERE od.SalesOrderID = o.SalesOrderID
GROUP BY OrderDate, ProductID;
GO
--Create an index on the view.
CREATE UNIQUE CLUSTERED INDEX IDX_V1
ON Sales.vOrders (OrderDate, ProductID);
GO
--This query can use the indexed view even though the view is
--not specified in the FROM clause.
SELECT SUM(UnitPrice*OrderQty*(1.00-UnitPriceDiscount)) AS Rev,
OrderDate, ProductID
FROM Sales.SalesOrderDetail AS od
JOIN Sales.SalesOrderHeader AS o ON od.SalesOrderID=o.SalesOrderID
AND ProductID BETWEEN 700 and 800
AND OrderDate >= CONVERT(datetime,'05/01/2002',101)
GROUP BY OrderDate, ProductID
ORDER BY Rev DESC;
In the above code block, Sales.SalesOrderDetail and Sales.SalesOrderHeader are base tables.
Say suppose there are some indexes on some of the columns of these base tables. Are these indexes used when we write a query in which indexed view is mentioned
in the from clause?
Thanks, Srikar
SO far as its a indexed view it wont use the indexes on base tables when you use it in a query as indexed view is persisted and exists as a physical object. SO it doent require definition to be substituted and data to be retrieved from the base objects.
The indexes will come handy while populating the indexed view.
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page
Similar Messages
-
CC&B 2.3.1 - Custom indexes for base tables
Hi,
We are seeing a couple of statements in the database that could improve its performance with new custom indexes on base tables. Questions are:
- can we create new indexes on base tables ?
- is there any recommendations about naming, characteristics and location for this indexes ?
- is there any additional step to do in CC&B in order to use the index (define metadata or ...) ?
Thanks.
Regards.Hi,
if it necessary You can crate custom index.
In this situation You should follow naming convention from Database Design Standards:
Indexes
Index names are composed of the following parts:
+[X][C/M/T]NNN[P/S]+
+• X – letter X is used as a leading character of all base index names prior to Version 2.0.0. Now the first character of product owner flag value should be used instead of letter X. For client specific implementation index in Oracle, use CM.+
+• C/M/T – The second character can be either C or M or T. C is used for control tables (Admin tables). M is for the master tables. T is reserved for the transaction tables.+
+• NNN – A three-digit number that uniquely identifies the table on which the index is defined.+
+• P/S/C – P indicates that this index is the primary key index. S is used for indexes other than primary keys. Use C to indicate a client specific implementation index in DB2 implementation.+
Some examples are:
+• XC001P0+
+• XT206S1+
+• XT206C2+
+• CM206S2+
Warning! Do not use index names in the application as the names can change due to unforeseeable reasons
There is no additional metadata information for indexes in CI_MD* tables - because change of indexes does not influence generated Java code.
Hope that helps.
Regards,
Bartlomiej -
How to update view without modifying the base table ?
Hi Experts , I need help in two qurstions
1. How to update a view without modifying the base table ?
2. How to write a file unix operating system in pl/sql ? is there any built in procedure is there ?
Thank youHi,
I'm not sure what you're asking in either question. It would help if you gave a specific example of what you want to do.
SowmyRaj wrote:
Hi Experts , I need help in two qurstions
1. How to update a view without modifying the base table ?You can't.
Views don't contain any data; they just query base tables.
You can change the definition of a view (CREATE OR REPLACE VIEW ...) so that it appears that the base table(s) have changed; that won't change the base tables.
2. How to write a file unix operating system in pl/sql ? is there any built in procedure is there ?The package utl_file has routines for working with files. -
Updating base table with Materialized View's data
Hi,
In order to update base table with MVs data, I am trying real time data transfer between two databases. One is Oracle 8i and other is Oracle 9i. I have created an updatable MV in 9i on a base table using database link. The base table is in 8i. Materialized View log is created in 8i on base table. MV has to be associated to some replication group, but I am not able to create replication group in 9i to which MV has to be associated. The required packages are not installed.
Replication packages are to be used to create replication group are :
/*Create Materialized View replication group*/
BEGIN
DBMS_REPCAT.CREATE_MVIEW_REPGROUP (
gname => 'TEST_MV_GRP',
master => 'TEST_DATA_LINK',
propagation_mode => 'ASYNCHRONOUS');
END;
But above block is giving error.
Can anyone suggest how to resolve this, or are there any other approaches (by not using replication packages) to update base table with MVs data ?
Thanks,
ShaileshYes, I created link between two databases and was able to update tables on 8i from 9i database using that link.
The error I am getting while creating replication group is :
ORA-06550
PLS-00201 : identifier 'SYS.DBMS_REPCAT_UTL2@'TEST_DATA_LINK' must be declared
ORA-06550
PLS-00201 : identifier 'SYS.DBMS_REPCAT_UNTRUSTED@'TEST_DATA_LINK' must be declared
ORA-06512 : at "SYS.DBMS_REPCAT_UTL", line 2394
ORA-06512 : at "SYS.DBMS_REPCAT_SNA_UTL", line 1699
ORA-06512 : at "SYS.DBMS_REPCAT_SNA", line 64
ORA-06512 : at "SYS.DBMS_REPCAT", line 1262
Is there any other approach which can be used to update base table with MVs data instead of using replication packages ?
Thanks,
Shailesh -
Dear All,
I have created a materialized view which refreshes on commit.materialized view is enabled query rewrite.I have created a materialized view log on the base table also While inserting into the base table it takes lot of time................Can u please tell me why?Dear Rahul,
Here is my materialized view..........
create materialized view mv_test on prebuilt table refresh force on commit
enable query rewrite as
SELECT P.PID,
SUM(HH_REGD) AS HH_REGD,
SUM(INPRO_WORKS) AS INPRO_WORKS,
SUM(COMP_WORKS) AS COMP_WORKS,
SUM(SKILL_WAGE) AS SKILL_WAGE,
SUM(UN_SKILL_WAGE) AS UN_SKILL_WAGE,
SUM(WAGE_ADVANCE) AS WAGE_ADVANCE,
SUM(MAT_AMT) AS MAT_AMT,
SUM(DAYS) AS DAYS,
P.INYYYYMM,P.FIN_YEAR
FROM PROG_MONTHLY P
WHERE SUBSTR(PID,5,2)<>'PP'
GROUP BY PID,P.INYYYYMM,P.FIN_YEAR;
Please help me if query enable rewrite does any performance degradation......
Thanks & Regards
Kris -
How to prevent materialized views from refreshing if source table is zero
any ideas?
Probably not what you were hoping for but here are a couple of ideas.
Your account shows - 113 (85 unresolved)
1. How about helping to keep the forum clean by reviewing your 85 unresolved previous questions and giving HELPFUL or ANSWERED credit to those that helped you in the past.
2. Read the FAQ at the top right of the page and post the information about your system and software so that we know what you are working with.
3. Ask your question in the body of the thread. Don't just say 'Any ideas'.
What exactly is your question? Is this an academic question or do you have an actual problem that needs to be addressed?
If you have an actual problem produce the DDL for the materialized view and information about the type of refresh that has been set up for it. Is there a materialized view log on the base table(s)?
The simple answer to your quest is to use REFRESH ON DEMAND and check the base table(s) before you do a manual
refresh. The best answer depends on what version of Oracle you are using and what your actual setup is. Are your
MVs in REFRESH GROUPS?. That can make a difference in the answer.
How can anyone help with this question if you won't provide the information needed(FAQ)? Why SHOULD anyone help if you show you don't appreciate the help by marking questions answered once you have been helped. -
Hi experts help me,
I have one requirment
there have two machine(plant) fert1,fert2 each one have some materilas.
from one of the plant will be goining to stop(fert1).
than we need featch the issued material from fert1 in reverse order to store it than post the meterial into fert2 based on the production number.
Please help me,
THANKS advance
Moderator message: "spec dumping", please work yourself first on your requirement.
Edited by: Thomas Zloch on Oct 29, 2010 1:54 PMHi,
I'm not sure what you're asking in either question. It would help if you gave a specific example of what you want to do.
SowmyRaj wrote:
Hi Experts , I need help in two qurstions
1. How to update a view without modifying the base table ?You can't.
Views don't contain any data; they just query base tables.
You can change the definition of a view (CREATE OR REPLACE VIEW ...) so that it appears that the base table(s) have changed; that won't change the base tables.
2. How to write a file unix operating system in pl/sql ? is there any built in procedure is there ?The package utl_file has routines for working with files. -
Index not using the base table
Hi,
In which scenario, a query will only use the index and not the base table. Please give me some example.
Thanks,
Santhosh
Edited by: Santhosh on Oct 23, 2012 2:45 AMChancal,
not always,
SQL> desc temp;
Name Null? Type
EMPNO NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
SQL> select empno from temp;
EMPNO
7369
7499
7521
7566
7654
7698
7782
7788
7839
7844
7876
7900
7902
7934
1057
15 rows selected.
SQL> select * from table(dbms_xplan.display_cursor);
PLAN_TABLE_OUTPUT
SQL_ID 3qt0w20pqj162, child number 0
select empno from temp
Plan hash value: 3800668828
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | | | 2 (100)| |
| 1 | TABLE ACCESS FULL| TEMP | 15 | 60 | 2 (0)| 00:00:01 |
13 rows selected.
SQL> alter table temp modify(empno not null);
Table altered.
SQL> select empno from temp;
EMPNO
1057
7369
7499
7521
7566
7654
7698
7782
7788
7839
7844
7876
7900
7902
7934
15 rows selected.
SQL> select * from table(dbms_xplan.display_cursor);
PLAN_TABLE_OUTPUT
SQL_ID 3qt0w20pqj162, child number 0
select empno from temp
Plan hash value: 472861760
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | | | 1 (100)| |
| 1 | INDEX FULL SCAN | IDX_TEMP | 15 | 60 | 1 (0)| 00:00:01 |
13 rows selected. -
Index Compression in SAP - system/basis tables?
Hi!
In thread Oracle comression in SAP environments the Oracle 10g feature index compression was discussed. We are now going to implement it also. SAP and Oracle say, this can be done for any index.
So we selected the biggest and the most frequently used indexes and analyzed them. We could save about 100GB disk space.
But here comes my question:
In the hitlist of our most frequently used and biggest Indexes there are also some basis table indexes.
A few samples:
BALHDR~0
BALHDR~1
BALHDR~2
BALHDR~3
BDCP~0
BDCP~1
BDCP~POS
BDCPS~0
BDCPS~1
CDCLS~0
CDHDR~0
D010INC~0
D010INC~1
D010TAB~0
D010TAB~1
DD01L~0
DD03L~5
DD07L~0
E071K~0
E071K~ULI
GVD_LATCHCHILDS~0
GVD_OBJECT_DEPEN~0
GVD_SEGSTAT~0
QRFCTRACE~0
QRFCTRACE~001
QRFCTRACE~002
REPOSRC~0
SCPRSVALS~0
SEOCOMPODF~0
SMSELKRIT~0
SRRELROLES~0
SRRELROLES~002
STXH~0
STXH~REF
STXL~0
SWW_CONT~0
TBTCS~1
TODIR~0
TRFCQOUT~5
USR02~0
UST04~0
VBDATA~0
VBMOD~0
WBCROSSGT~0
Is it really recommended to compress indexes of SAP Basis Tables also - especially in the area of Repository/Dictionary, t/qRFC and/or "Verbuchung" (VB...)?
Thanx for any hint and/or comment!
Regards,
VolkerHi Volkar,
I have succesfully tested the oracle index compression on ECC5 environment for the following tables in a sandbox environment;
ppoix
pcl2
pcl4
In total I saved around 60GB in the tablespaces.
Before compression I started a payroll run to see what time this will take without compression.
After compression of the indexes I re-executed the payroll which took exactly the same time as without compression (2 hours). So no impact on performance.
Also did an update statistics in DB13 -> no impact
With brtools: force update of specific table -> no impact
So we are seriously thinking about to take this into production.
I have also looked at BI environment but concluded that there was nothing to gain.
Unfortunately our infocubes are well build meaning that the fact tables contains the actual data and the corresponding dimension tables only the surrogate IDu2019s (SIDu2019s).
Those dimension tables are actually very small (64k) and not suitable for index compression.
Next step will be some Workflow tables.
Fe:
SWW_CONT~0 INDEX PSAPFIN 26.583.040
SWPNODELOG~0 INDEX PSAPFIN 15.589.376
SWWLOGHIST~0 INDEX PSAPFIN 13.353.984
SWWLOGHIST~1 INDEX PSAPFIN 8.642.560
SWW_CONTOB~0 INDEX PSAPFIN 8.488.960
SWPSTEPLOG~0 INDEX PSAPFIN 6.808.576
SWW_CONTOB~A INDEX PSAPFIN 6.707.200
SWWLOGHIST~2 INDEX PSAPFIN 6.507.520
SWW_WI2OBJ~Z01 INDEX PSAPFIN 2.777.088
SWW_WI2OBJ~0 INDEX PSAPFIN 2.399.232
SWWWIHEAD~E INDEX PSAPFIN 2.352.128
SWP_NODEWI~0 INDEX PSAPFIN 2.304.000
SWW_WI2OBJ~001 INDEX PSAPFIN 2.289.664
SWWWIHEAD~A INDEX PSAPFIN 2.144.256
SWPNODE~0 INDEX PSAPFIN 2.007.040
SWWWIRET~0 INDEX PSAPFIN 2.004.992
SWW_WI2OBJ~002 INDEX PSAPFIN 1.907.712
If you would like to know, I can post the results on workflow tables (indexes) on ECC6 environment.
Please rewards some point if you like.
Regards,
Stephan van Loon -
Changes of a base table PK/unique index
After alter a new column to a base table PK on the server, recreate the snapshot and run MGP the new unique index value did not update table C$ALL_INDEXES in client database conscli.odb. After sync two unique indexes were created for current table in lite.odb, one new and one old that still remains in table C$ALL_INDEXES in the client database conscli.odb.
Please, help me resolve this problem!Drop and recreate the publication item using the APIs, then reset the metadata. That should fix the issue.
-
To Use Cursor or TYPE table Index by PLS_integer
Hi All,
Let's see if I have table with no. of records 19,26,20,000.
If I want to loop through all the records which will be a optimized way To Use Cursor or TYPE table Index by PLS_integer.
Please guide.
Thanks.What is it you want to do to/with the rows you're looping through?
Ideally you want to avoid looping, as that's row by row (aka slow by slow) processing and it's expensive time-wise.
If you're doing DML (insert/update/delete) then you're best off doing it in one sql statement, rather than looping. -
Space in bytes used by a single index in given table space
Hi All,
How can i find a table space used by index in bytes
Eg:
suppose i have a table space USERS and i have a table say customer . one index defined on table customer called CUSTOMER_UQ and mapped to table to table space USERS . How can i find the bytes used by object CUSTOMER_UQ in table space USERS.
ThanksThe used space in Karthik's example is the number of bytes actually used by entries in the index, not the amount of space allocated to the index itself.
To find out how much space in disk is allocated to the index you can use (as the owner of the index) something like:
SELECT bytes FROM user_segments
WHERE segment_name = <index name>You could also use all_segments or dba_segments if you have access as another user, but you would also need to specify the owner name.
John -
Best way of Using Index on a Table.
I am trying to understand the phenomena of using INDEX on a Table
need some guidance!!!
Let us take this scenario
I have a table "MYRECORD" which has 4 attributes(or coulombs)
1. "STATE" (varchar) // this can have 49 different values like newyork, dehli etc
2. "YEAR" //a year like 2007
3. "MONTH" //a month like JAN,FEB etc
4. "CAT" (int) // type(category) of data represented by values 0 to 40
with a PRIMARY KEY(STATE,YEAR,MONTH,CAT)
now i will create index
1. INX_myrecord (STATE,YEAR,MONTH) on table MYRECORD
so now my question is
1. what is the effect on performance of DB it makes?
2. when I use a query
SELECT * FROM MYRECORD WHERE STATE="dehli" AND YEAR=2007 AND MONTH="JAN";
how will it get processed if index is created and not created.
3. how can I refer a index by name in a query if so possible?
Cheers,
UD
Message was edited by:
UDAYYou have edited your post. Now you have a primary key consisting of state, year, month and cat which makes an index on state, year and month useless as the already existing primary key can provide for retrieval of rows by index. If you don't have other columns - or just few other not being large varchar2 columns - you should have created the table as an IOT (Index Organized Table - avoiding to have separate table and index containing - nearly - the same data) in the first place.
As a primary key by definition can contain only unique non null values, a query like SELECT * FROM MYRECORD WHERE STATE='dehli' AND YEAR=2007 AND MONTH='JAN' cannot give you more than the number of distinct cat values (0 .. 40) + 1 (if cat can be null - presumed one/some of the corresponding state, year and month is not null)
The information processing depends principally of the query, the mere presence of an index does not make sure it will be used. If an index is used it means the index will be searched first then the table rows will be accessed by rowids contained in the index (usually a single row or a range of rows - a rather small number of them - is retrieved this way, your select for example). Submitting something like SELECT * FROM MYRECORD WHERE YEAR=2007 AND cat=33 would most likely produce a full table scan of myrecord table ignoring the primary key.
Regards
Etbin -
How to make use of Index of a table in report to fetch data?
Hi,
I need a sample code for select statement which is making use of INDEX of a table
to fetch data.
Doubt:
Can I fetch all the fields in the table by passing certain key fields of INDEX in where condition?Hi Raja,
1) Mention the fields that you wish from database table (incase you don't need all the fields from the database table).
2) Don't use the INTO CORRESPONDING FIELDS OF TABLE ztable clause.
3)Instead use INTO TABLE ztable (But take care that during the declaration of the ztable, the fields declared are in order that in database table to fetch the Records in sequence).
Please Find the Syntax and Code Below..
SELECT * FROM <TABLE>
WHERE <WHERE>
%_HINTS ORACLE 'INDEX("<TABLE>~<INDEX ID")'.
SELECT carrid
INTO TABLE t_spfli
FROM spfli
WHERE carrud IN s_carrid AND
connid IN s_connid
%_HINTS ORACLE 'INDEX("&SPFLI&" "SPFLI~XXX")'.
Hope this Is helpFul
Thanks
kalyan -
Why Oracle not using the correct indexes after running table stats
I created an index on the table and ran the a sql statement. I found that via the explain plan that index is being used and is cheaper which I wanted.
Latter I ran all tables stats and found out again via explain plan that the same sql is now using different index and more costly plan. I don't know what is going on. Why this is happening. Any suggestions.
ThxI just wanted to know the cost using the index.
To gather histograms use (method_opt is the one that causes the package to collect histograms)
DBMS_STATS.GATHER_SCHEMA_STATS (
ownname => 'SCHEMA',
estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE,
block_sample => TRUE,
method_opt => 'FOR ALL COLUMNS SIZE AUTO',
degree => 4,
granularity => 'ALL',
cascade => TRUE,
options => 'GATHER'
);
Maybe you are looking for
-
3rd generation - windows 7 wont recognize device
windows 7 says that the usb attached device is not working properly / not recognized by windows????
-
Can't get photoshop elements to open
I have used photoshop many times on this computer and have never had a problem until now. I tried to open it on my computer and I double clicked on the icon as well as went to "start" "programs" to get it to open and it won't do anything. When I ra
-
PDF exports look terrible - white lines in text
I have been u sing indesign for years and years all of the sudden my pdf exports look terrible. The images are pixelated and the text has white lines in it. I used these pdf previews for my clients and I certainly cant use what Im getting from INDD r
-
I have a 6 minute video that my client wants to proof via an ftp site. They want me to upload the file that they can then download and view on a PC. What export settings and sizings should be used for this to work on the PC and still be a reasonable
-
Integration with iProcurement application
I'm trying to integrate Oracle iProcurement application's main business process, i.e browsing through shopping catalog, adding items to the shopping cart, saving and retrieving shopping cart, retrieving the pending requisitions etc, with my web appli