Why do we need query rewrite enabled for a function-based index?
Oracle 9i
========
I have searched a few sites but could not find any content on it. The question is why do we need to implement query rewrite enabled when we are trying out a function-based index?
Thanks in advance.
You don't, that's a legacy requirement from the early days of function based indexes in Oracle 8i. Here's a quick example running under 9.2.0.6
drop table t1;
create table t1 as
select
from
all_objects
where
rownum <= 30000
create or replace function pl_func(i_vc varchar2)
return varchar2
deterministic
as
begin
return soundex(i_vc);
end;
-- set the worst case scenario
alter session set query_rewrite_enabled = false;
alter session set query_rewrite_integrity = enforced;
create index t1_i1 on t1(pl_func(object_name));
execute dbms_stats.gather_table_stats(user, 't1')
set autotrace traceonly explain
select
object_name
from t1
where pl_func(object_name) = 'T513'
set autotrace offResults (after set feedback off)
SQL> @temp
Execution Plan
Plan hash value: 1429545322
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 27 | 675 | 10 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 27 | 675 | 10 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T1_I1 | 27 | | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("TEST_USER"."PL_FUNC"("OBJECT_NAME")='T513')
SQL> spool offRegards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk
Similar Messages
-
Syntax for existing function-based index
Hi:
I am on 10.2.0.3.
Listed below is the list of indexes and index columns on one of the tables. Aparantly one of the columns (SYS_NC00220$ ) is in reality a function-based index.
Anybody knows how to get SQL syntax for this index? TIA.
INDEX_NAME UNIQUENES COLUMN_NAME COLUMN_POSITION
PS0BI_HDR NONUNIQUE BILL_TO_CUST_ID 1
PS0BI_HDR NONUNIQUE BUSINESS_UNIT 2
PS0BI_HDR NONUNIQUE SYS_NC00220$ 3
PS1BI_HDR NONUNIQUE BILL_STATUS 1
PS1BI_HDR NONUNIQUE BUSINESS_UNIT 2
PS1BI_HDR NONUNIQUE SYS_NC00220$ 3
PS2BI_HDR NONUNIQUE CONTRACT_NUM 1
PS2BI_HDR NONUNIQUE BUSINESS_UNIT 2
PS2BI_HDR NONUNIQUE SYS_NC00220$ 3
PSABI_HDR NONUNIQUE INVOICE 1
PSABI_HDR NONUNIQUE BILL_TO_CUST_ID 2
PSABI_HDR NONUNIQUE BUSINESS_UNIT 3
PSABI_HDR NONUNIQUE BILL_STATUS 4
PSBBI_HDR UNIQUE PROCESS_INSTANCE 1
PSBBI_HDR UNIQUE BUSINESS_UNIT 2
PSBBI_HDR UNIQUE INVOICE 3
PS_BI_HDR UNIQUE BUSINESS_UNIT 1
PS_BI_HDR UNIQUE SYS_NC00220$ 2query user_ind_expressions and look for COLUMN_EXPRESSION.
this will give you expression. -
Why sender agreement need not to create for IDOC
Hi Experts,
why sender agreement need not to create for idocPlease check these related discussions:
Re: Question on sender agreement
Re: IDOC and HTTP Adapters - sender agreement ??
Re: ** Sender Agreement is required for RFC but not IDoc, XI, & HTTP.. Why ?
Many threads with the same Q are answered on SDN....so if you search you can find the correct answer that you need!
Regards,
Abhishek. -
Why do u need a custom structure for creating a custom bapi
Hi ,
why do u need a custom structure for creating a custom bapi.Hi,
Once any Bapi realeased the structures it is using freezed to this bapi, the structure becomes specific to this Bapi, we can not make any changes over there. That is why we need custom structure for creating a custom bapi. -
Does Bluetooth need to be enabled for cloud to work?
Does Bluetooth need to be enabled for cloud to work?
No, the two are unrelated. You need to be connected to either WiFi or 3G to use iCloud (or any online feature). Bluetooth for the iPad only supports keyboards and audio out.
-
I have enabled all cookies, yet some sites say cookies need to be enabled for me to get access. How do I fix this?
First check the settings and try all of the options in the [[websites say cookies are blocked]] article.
In addition to the above, another possible cause is the file that stores cookies is corrupt, if that is the case deleting the file should fix the problem. First you need to locate your profile folder, for details of how to do that see the [[profiles]] article. Once you have opened the profile folder, close Firefox and either delete or rename cookies.sqlite, when you restart Firefox that file will be re-created. -
Why Segment shrink is not supported for tables with function-based indexes
As we all know , Segment shrink is not supported for tables with function-based indexes.
But i'm very confused .
Why Segment shrink is not supported for tables with function-based indexes ?? what's its essential?Creating a function based index creates a hidden virtual column (you'll see it if you query user_tab_cols) and once you index a virtual column you can no longer shrink the table:orcl> create table t1(c1 number,c2 as (c1 * 2)) segment creation immediate;
Table created.
orcl> alter table t1 enable row movement;
Table altered.
orcl>
orcl> alter table t1 shrink space;
Table altered.
orcl> create index i2 on t1(c2);
Index created.
orcl> alter table t1 shrink space;
alter table t1 shrink space
ERROR at line 1:
ORA-10631: SHRINK clause should not be specified for this object
orcl>so the issue is not with function based indexes per se, it is a level beneath that. Perhaps because the virtual column has no physical existance, when the row is moved there is no reason for Oracle to realize that an index needs updating? I haven't attempted to reverse engineer this, I would be interested to know if anyone else has. -
Does this query need function based index?
Hello All,
I have a strange problem. I have a table DM_T_CLEAN_EXCEPTION_LOG and I am doing a query in reports as follows:
select COUNT(*) NO_OF_ALL_RECORDS
FROM DM_T_CLEAN_EXCEPTION_LOG
WHERE CREATE_DATE > to_date(to_char(sysdate -1 ,'dd-mon-yyyy') || ' 05:00:00PM' ,'dd-mon-yyyy hh:mi:sspm')
AND EXCEPTION_SEVERITY = :EXCEPTION_SEVERITY
AND EXCEPTION_DESCRIPTION = :EXCEPTION_DESCRIPTION
Now I created indexes on CREATE_DATE, EXCEPTION_SEVERITY and EXCEPTION_DESCRIPTION. It says Index Skip Scan so I think it is slow. I tried even creating function based index on create_date using the to_date(to_char(create_date,'dd-mon-yyyy') but then it does a full table scan. Can anyone tell me what is the right way in this situation?
ThanksIt says Index Skip Scan so I think it is slow.Is it really slow or do you only think that it is slow ?
If it is slow, please show us the explain plan with cardinalities, so we can figure out if an index on (exception_severity,exception_description,create_date) is more beneficial than your current one on (create_date,exception_severity,exception_description).
Regards,
Rob. -
Function-Based Index enabling.
Hi...
I'm trying to create a function-based index along the lines of:
CREATE INDEX x_ssn4
ON table_y(SUBSTR(ssn,6,4))
UNRECOVERABLE;
...so as to be able to query the final 4 digits of social security numbers. Problem is that the above elicits an ORA-00439 "feature not enabled" message. I'm running 8.1.6 and have tried setting the Oracle parameter QUERY_REWRITE_ENABLED to 'TRUE' via an ALTER SESSION command, but to no avail.
Anyone know how to 'turn the feature on'?
Thanks, Rob<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Rick Post:
I've always done it by logging on as SYS and executing a 'grant query rewrite to myuser'.
<HR></BLOCKQUOTE>
Thanks... but turns out that the privilege is not really the issue, as the ALTER SESSION command works. I figured out that the problem was the setting for COMPATIBLE. It pointed to 8.0.0 instead of 8.1.x which is what was needed to permit function-based indexing.
~Rob
null -
How to create function based index for TO_CHAR
i need to create a function based index for the function to_char.when i tried ,i got an error,"only pure function can be indexed".what the error really means, help me in creating the index to reduce my query cost.
It works fine on my database. version 9iR2
create index IDX_TO_CHAR on emp(to_char(hiredate,'YYYY-MM-DD HH24:MI:SS'));
explain plan for
select hiredate from emp where to_char(hiredate,'YYYY-MM-DD HH24:MI:SS')='1981-05-01 00:00:00';
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
| 0 | SELECT STATEMENT | | 1 | 8 | 2 (50)|
| 1 | TABLE ACCESS BY INDEX ROWID| EMP | 1 | 8 | 2 (50)|
|* 2 | INDEX RANGE SCAN | IDX_TO_CHAR | 1 | | 2 (50)|
Predicate Information (identified by operation id):
2 - access(TO_CHAR("EMP"."HIREDATE",'YYYY-MM-DD HH24:MI:SS')='1981-05-01 00
:00:00')Yours seem like a tuning issue, so why not give us your sql and execution plan and so on.
maybe there is other ways to tune your sql than creating a function based index? -
Function-Based Indexes for 8.1.6 SE and 9iAS
I have installed the 9iAS Portal into a 8.1.6 SE database, and I cannot get the Function-Based Index feature to turn on. I have set QUERY_REWRITE_INTEGRITY=trusted, QUERY_REWRITE_ENABLED=true and COMPATIBLE="8.1.0.0.0". The feature will still not enable.
I have 2 questions:
1. Is there anything else I can do to turn this feature on.
2. If not, do I have to upgrade to 8.1.7 or to 8.1.* Enterprise Edition to make use of this feature.Could you give the statement for the index you have used, the query you try to do and a description of columns and datatypes of the table? How do you know/check that is doesn't work? Execution plan, errors?...
-
Query not considering function based index in oracle 11g
I have a query which used Function Based Index when run in oracle 9i but when I run the same query
without any changes, it does not consider index. Below is the query:
SELECT distinct patient_role.domain_key, patient_role.patient_role_key,
patient_role.emergency_contact_name,
patient_role.emergency_contact_phone, patient_role.emergency_contact_note,
patient_role.emergency_contact_relation_id,
patient_role.financial_class_desc_id, no_known_allergies, patient_role.CREATED_BY,
patient_role.CREATED_TIMESTAMP,
patient_role.CREATED_TIMESTAMP_TZ, patient_role.UPDATED_BY, patient_role.UPDATED_TIMESTAMP,
patient_role.UPDATED_TIMESTAMP_TZ,
patient_role.discontinued_date
FROM encounter, patient_role
WHERE patient_role.patient_role_key = encounter.patient_role_key
AND UPPER(TRIM(leading :SYS_B_0 from encounter.account_number)) = UPPER(TRIM(leading :SYS_B_1 from
:SYS_B_2))
AND patient_role.discontinued_date IS null
AND encounter.discontinued_date IS null ;
Index definition:
CREATE INDEX "user1"."IX_TRIM_ACCOUNT_NUMBER" ON "user1."ENCOUNTER" (UPPER(TRIM(LEADING
'0' FROM "ACCOUNT_NUMBER")), "PATIENT_ROLE_KEY", "DOMAIN_KEY", "DISCONTINUED_DATE")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT)
TABLESPACE "user1"
Database : Oracle 11g (11.2.0.3)
O/S : Linux 64 bit (the query does not consider index even on windows os)
Any suggestions?
-Onkar
Edited by: onkar.nath on Jul 2, 2012 3:32 PMOnkar,
I don't appreciate you posting this question in several forums at the same time.
If I would know you also posted this on Asktom, I wouldn't even have bothered.
As to your 'issue':
First of all: somehow cursor_sharing MUST have been set to FORCE. Oracle is a predictable system, not a fruitmachine.
Your statement the '0' is replaced by a bind variable anyway is simply false. If you really believe it is not false, SUBMIT a SR.
But your real issue is not Oracle: it is your 'application', which is a mess anyway. Allowing for alphanumeric numbers is a really bad idea.
Right now you are already putting workaround on workaround on workaround on workaround.
Issue is the application: it is terminal., and you either need to kill it, or to replace it.
Sybrand Bakker
Senior Oracle DBA -
Query Transformation in Function Based Index's Expression
Hi All,
I am having a wired issue with Function Based Indexes on Orcale 10.2.0.3 running on Solaris 5.9.
I have created two FBI on two tables using following syntax.
CREATE INDEX EQHUB.IDX_BBO_WRT_DES_FBI ON EQHUB.BBO_WARRANT_PRICING (CASE WHEN latest_version_flag = 'Y' THEN 1 ELSE NULL END);
CREATE INDEX EQHUB.IDX_BBO_DES_FBI ON EQHUB.BBO_DESCRIPTIVE_DATA (CASE WHEN latest_version_flag = 'Y' THEN 1 ELSE NULL END);
For the second command (IDX_BBO_DES_FBI), when i query DBA_IND_EXPRESSIONS view, i found that Oracle has done some kind of QUERY TRANSFORMATION (?) and converted
FBI expression to CASE "LATEST_VERSION_FLAG" WHEN 'Y' THEN 1 ELSE NULL END.At the same time,EXPRESSION on first index is not changed.
Now,my question is what has made transformation to occure only for second index.
I also found that inspite of highly SELECTIVE nature of both the indexes, only SECOND index is being used by CBO (for which trasnformation occured)
and IDX_BBO_WRT_DES_FBI is not being used(FTS is happening instead).
Query is using same expression for both the tables as
(CASE WHEN latest_version_flag = 'Y' THEN 1 ELSE NULL END)=1
INDEX_NAME TABLE_NAME COLUMN_EXPRESSION
IDX_BBO_WRT_DES_FBI BBO_WARRANT_PRICING CASE WHEN "LATEST_VERSION_FLAG"='Y' THEN 1 ELSE NULL END
IDX_BBO_DES_FBI BBO_DESCRIPTIVE_DATA CASE "LATEST_VERSION_FLAG" WHEN 'Y' THEN 1 ELSE NULL ENDI read that expression should be evaluated including CASE of characters and spaces in query.Is that true?
Appreciating responses in advance.Randolf.
It's a shame that I forgot to look into the full execution plan information to check how Oracle really handles my queries.
Look here(edited for clarity):
explain plan for
select /*+ case1 ordered use_nl(x, y) */ count(case c1
when '1' then 1
when '2' then 2
when '3' then 3
else 4
end) from
(select level from dual connect by level <= 300000) x,
(select
from t1
) y;
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 2 | 5 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 2 | | |
| 2 | NESTED LOOPS | | 3 | 6 | 5 (0)| 00:00:01 |
| 3 | VIEW | | 1 | | 2 (0)| 00:00:01 |
| 4 | CONNECT BY WITHOUT FILTERING| | | | | |
| 5 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 6 | TABLE ACCESS FULL | T1 | 3 | 6 | 3 (0)| 00:00:01 |
Column Projection Information (identified by operation id):
1 - (#keys=0) COUNT(CASE WHEN "T1"."C1"='1' THEN 1 WHEN "T1"."C1"='2' THEN
2 WHEN "T1"."C1"='3' THEN 3 ELSE 4 END )[22]
2 - (#keys=0) "T1"."C1"[CHARACTER,1]
4 - "DUAL".ROWID[ROWID,10], LEVEL[4]
5 - "DUAL".ROWID[ROWID,10]
6 - "T1"."C1"[CHARACTER,1]
32 rows selected.
explain plan for select /*+ case2 ordered use_nl(x, y) */ count(case
when c1 = '1' then 1
when c1 = '2' then 2
when c1 = '3' then 3
else 4
end) from
(select level from dual connect by level <= 300000) x,
(select
from t1
) y;
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 2 | 5 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 2 | | |
| 2 | NESTED LOOPS | | 3 | 6 | 5 (0)| 00:00:01 |
| 3 | VIEW | | 1 | | 2 (0)| 00:00:01 |
| 4 | CONNECT BY WITHOUT FILTERING| | | | | |
| 5 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 6 | TABLE ACCESS FULL | T1 | 3 | 6 | 3 (0)| 00:00:01 |
Column Projection Information (identified by operation id):
1 - (#keys=0) COUNT(CASE WHEN "T1"."C1"='1' THEN 1 WHEN "T1"."C1"='2' THEN
2 WHEN "T1"."C1"='3' THEN 3 ELSE 4 END )[22]
2 - (#keys=0) "T1"."C1"[CHARACTER,1]
4 - "DUAL".ROWID[ROWID,10], LEVEL[4]
5 - "DUAL".ROWID[ROWID,10]
6 - "T1"."C1"[CHARACTER,1]As you exactly mentioned, I was executing different SQL but actually same queries!
Thanks for pointing my flaws.
PS) OP, forgive me for bothering you with off-topic things. :)
================================
Dion Cho - Oracle Performance Storyteller
http://dioncho.wordpress.com (english)
http://ukja.tistory.com (korean)
================================
Edited by: Dion_Cho on Feb 10, 2009 5:45 AM
Typo -
Err ORA-00439 feature not enabled: function-based indexes
How can I enable function based indexes?
Database Version is 8i Release 8.1.6.0.0.
I've done the following steps:
The init-parameter compatible is set to 8.1.0.0.0.
I've altered the session parameters
QUERY_REWRITE_INTEGRITY to TRUSTED and
QUERY_REWRITE_ENABLED to TRUE.
But it still doesn't work.
I would appreciate your help.
MartinFunction Based Index feature is not available in the Standard Edition of Oracle. This feature is available ONLY in the Enterprise and Personal Editions.
Use the V$OPTION view to see the list of installed options.
If the option is installed, you will see for "Function-based indexes":
PARAMETER VALUE
Function-based indexes TRUE
null -
How to define error message for function based index violation?
Hi,
I am generating Forms 6i from Designer 6i. I have a function based index to enforce case insensitive name uniqueness. With check constraints I can specify constraint violation error messages that will be displayed in Forms at runtime if needed. How can I do this with function based index constraints?
Regards,
TamasOK, problem sorted.
You need to create a check constraint with the same name as the new index, but don't enable it.
Maybe you are looking for
-
My thunderbird has moved to be in English, how do I get it back to Danish
Jeg opdaterede og nu er alt på engelsk
-
How to add icons to avant?
Well how do you do it? I thought it was drag and drop but that doesnt work and cant find much info on it either?
-
New to camera raw and have a basic question
Hello, I have just started playing with camera raw and when I make changes, and say done, I am able to open that image up and continue with the corrections, which is great. but..... If I open up an image that has been edited in camera raw, and I want
-
Adobe Reader 11 Can Not Reach a Reliable Source
I am tyring to install Adobe reader 11. I get Adode reader acn not access a reliable source. I used Google Crome, Firefoc and IE*. I get the sam error.
-
Internal microphone not responding
My internal microphone will not work on my HP pavilion dv6000 notebook (specifically dv6448se). Vista claims the microphone is active, but it won't pick up a signal. I'm running the most up to date conexant audio drive version 4.33.1.61. I've tried