Function-based spatial indexes
hello,
I'm using a function-based spatial index, which I've set up in a way similar to Oracle's examples in the Spatial documentation. Here's the basic idea:
create table places (
place_id not null
primary key,
latitude number,
longitude number
-- This function is used to create an MDSYS.SDO_GEOMETRY object
-- as part of the Oracle Spatial indexing of the latitude and
-- longitude.
create or replace function get_long_lat_pt(
longitude in number,
latitude in number)
return MDSYS.SDO_GEOMETRY deterministic
is
begin
if latitude is null or longitude is null
then
return null;
else
return mdsys.sdo_geometry(2001, 8307,
mdsys.sdo_point_type(longitude, latitude, NULL), NULL, NULL);
end if;
end;
show errors
INSERT INTO USER_SDO_GEOM_METADATA
VALUES ('PLACES', 'schema_name.GET_LONG_LAT_PT(LONGITUDE,LATITUDE)',
MDSYS.SDO_DIM_ARRAY(
MDSYS.SDO_DIM_ELEMENT('Longitude', -180, 180, 0.00000005),
MDSYS.SDO_DIM_ELEMENT('Latitude', -90, 90, 0.00000005)),
8307
-- Create Oracle Spatial function-based index
CREATE INDEX places_long_lat_idx ON places(get_long_lat_pt(longitude, latitude))
INDEXTYPE IS mdsys.spatial_index PARAMETERS('layer_gtype="POINT"');
All of this works just fine. But then I try to do a nearest neighbor calculation:
select /*+ INDEX(places places_long_lat_idx) */ place_id
FROM places WHERE
SDO_NN(
get_long_lat_pt(longitude,latitude), -- table values
get_long_lat_pt(-71.1482, 42.3367), -- an arbitrary point
'sdo_num_res=2') = 'TRUE'
and I get this:
ERROR at line 1:
ORA-13249: SDO_NN cannot be evaluated without using index
ORA-06512: at "MDSYS.MD", line 1723
ORA-06512: at "MDSYS.MDERR", line 17
ORA-06512: at "MDSYS.PRVT_IDX", line 27
It's as though Oracle isn't using the function-based index inside my SDO_NN call, even with a INDEX hint. I am stumped.
Just for kicks I tried to do a query using SDO_FILTER instead. I get:
ERROR at line 1:
ORA-13268: error obtaining dimension from USER_SDO_GEOM_METADATA
ORA-06512: at "MDSYS.MD", line 1723
ORA-06512: at "MDSYS.MDERR", line 8
ORA-06512: at "MDSYS.SDO_3GL", line 365
I am using Oracle 9.0.1.0.0, and I set QUERY_REWRITE_ENABLED=TRUE and QUERY_REWRITE_INTEGRITY=TRUSTED as noted in the Spatial documentation.
Any clues?
Thanks,
Greg
Greg,
The only times I have seen this error is when the
two parameters you mention are not set properly for the session.
I have a feeling that the parameters (QUERY_REWRITE_ENABLED,
and QUERY_REWRITE_INTEGRITY) are not getting the right values.
Can you verify this by doing a
show parameter QUERY_REWRITE_INTEGRITY
and
show parameter QUERY_REWRITE_ENABLED
from the session from where you are trying to execute
the Spatial operator.
Or you can try setting them for the session by
alter session set parameter=value
to see if it makes a difference.
thanks
siva
Similar Messages
-
Unable to create function based spatial index
Maybe someone can help me. I can't seem to find the answer for what I'm doing here.
I'm trying to create a function based spatial index - so that I can utilize coordinates in tables when I have no SDO_GEOMETRY column.
Is there a fundamental problem with trying to do this or is it something syntactical?
Executing the following sql is giving me this error, while I'm trying to create the spatial index:
--create some table
CREATE TABLE "ZZ_ACTIVITIES"
( "DESCRIPTION" VARCHAR2(50 BYTE),
"CREW" VARCHAR2(50 BYTE),
"LATITUDE" NUMBER DEFAULT 0.0,
"LONGITUDE" NUMBER DEFAULT 0.0
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS NOLOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "MAP_NA_Q406" ;
--create the function that takes an srid, and x/y and returns an SDO_GEOMETRY
create or replace function get_geometry(p_srid in number,
p_x in number,
p_y in number)
return mdsys.sdo_geometry deterministic;
Is
Begin
Return MDSYS.SDO_GEOMETRY(2001,p_srid,mdsys.sdo_point_type(p_x,p_y,NULL),NULL,NULL);
End observation;
--insert sdo metadata
INSERT INTO USER_SDO_GEOM_METADATA(
TABLE_NAME,
COLUMN_NAME,
DIMINFO,
SRID
) VALUES (
'ZZ_ACTIVITIES',
'GET_GEOMETRY(8307,LATITUDE,LONGITUDE)',
MDSYS.SDO_DIM_ARRAY(
SDO_DIM_ELEMENT
'LONGITUDE',
-180,
180,
0.5
SDO_DIM_ELEMENT
'LATITUDE',
-90,
90,
0.5
8307
--create the index. (THIS IS WHERE THE ERROR IS THROWN)
CREATE INDEX zz_activities_location_sidx ON ZZ_ACTIVITIES(GET_GEOMETRY(8307,LATITUDE,LONGITUDE)) INDEXTYPE IS MDSYS.SPATIAL_INDEX parameters('layer_gtype=POINT');
The error returned is;
ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
ORA-13203: failed to read USER_SDO_GEOM_METADATA view
ORA-13203: failed to read USER_SDO_GEOM_METADATA view
ORA-06512: at "MDSYS.SDO_INDEX_METHOD_10I", line 10Hi,
To follow up, the below code resolved the issue:
create index EQX_OKC_K_LINES_B_N4 on okc_k_lines_b(apps.eqx_oklb_term_date_nvl(date_terminated))
logging
tablespace eqixdata
noparallel;
-- qualifying the custom function name with schema name resolved the issue.
Thanks,
Rahul -
Problem with function-based spatial index in 10g
hi,
the document's example doesn't work anymore.
http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10826/sdo_exten.htm#sthref721
when i try to create the index i get the following error message:
create index LONG_LAT_TABLE_IDX on LONG_LAT_TABLE(get_long_lat_pt(longitude,latitude)) indextype is mdsys.spatial_index
ERROR at line 1:
ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
ORA-13249: internal error in Spatial index: [mdidxrbd]
ORA-13249: Error in Spatial index: index build failed
ORA-13249: Error in spatial index: [mdrcrtxfergm]
ORA-13249: Error in spatial index: [mdpridxtxfergm]
ORA-29400: data cartridge error
ORA-00904: "XXX"."GET_LONG_LAT_PT": invalid identifier
ORA-06512: at "MDSYS.SDO_INDEX_METHOD_10I", line 10
ORA-06512: at line 1
I'm not sure, but I think this problem occured in one special version of 9i...
thanks in advance,
michael
Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining optionsHi Michael,
Do you have a user named XXX on your system? Are you creating the index as XXX?
I logged in as scott, followed the example, and had no problems.
SQL> create index LONG_LAT_TABLE_IDX on
LONG_LAT_TABLE(get_long_lat_pt(longitude,latitude))
indextype is mdsys.spatial_index;
Index created.
SQL> SQL> select name from LONG_LAT_TABLE a
where sdo_filter(get_long_lat_pt(a.longitude,a.latitude),
sdo_geometry(2001, 8307,
sdo_point_type(10,10,NULL), NULL, NULL)
)='TRUE';
NAME
Place1
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options -
Oracle documentation on "How Function-Based Indexes Work" states that for the creation of a function-based index in the user's own schema, the user must be granted the QUERY REWRITE system privileges. And MUST have the following initialization parameters defined to create a function-based index:
QUERY_REWRITE_INTEGRITY set to TRUSTED
QUERY_REWRITE_ENABLED set to TRUE.
I have created a function-based unique index, which uses the SQL function DECODE(). But the user doesn't have the QUERY REWRITE sytem privilege. The user has the following privileges:
CREATE PROCEDURE
CREATE SEQUENCE
CREATE SESSION
CREATE TABLE
CREATE TRIGGER
CREATE VIEW
And also the initialization parameters for QUERY_REWRITE_INTEGRITY and QUERY_REWRITE_ENABLED are set to their DEFAULT values as follows:
QUERY_REWRITE_INTEGRITY set to ENCFORCED
QUERY_REWRITE_ENABLED set to FALSE.
Note: The index is an unique index for data integrity purpose. I am using Oracle 9.2.0.6 version.
Kindly explain me the reason how the function-based index is created without the system privilege and the initialization parmaters defined as stated in the Oracle9i Database Administrator's Guide Release 2 (9.2).You can change those parameter at session level as well.
Following link would be helpful:
http://asktom.oracle.com/pls/ask/f?p=4950:8:2552324147195810457::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:667694821129
Jaffar -
URGENT - Function based indexes
Hi,
I have a table with huge amount of data and hence I have created
a function-based (Upper) index on one of the character NOT
NULL field which is very likely to be used for query purposes.
First of all though I can create ordinary normal field based
indexes in my user I cannot create a function-based index, why
That had to be created thru SYS user. Secondly I my query
invloving this function is not using the index and instead doing
a full-table scan. Problem outlined below :
Table : PLZPOST, USER / OWNER : PARTNER, FIELD : ORT
INDEX created on UPPER(ORT) in SYS user -
Create index upper_plz_ort on partner.plzpost (upper(ort))
When I give any of the following queries instead of using the
resp. index as mentioned in Oracle DOC it just does a full table
scan (checked thru Explain Plan) :
select * from PLZPOST where upper(ort) is not null;
select * from PLZPOST where upper(ort) like upper('saar%')
select * from PLZPOST where upper(ort) = 'SAARBRUECKEN'
etc etc
If anyone has used Function-based indexes in Oracle 8i could you
please tell me where am I going wrong. Is it because my Table
belongs to PARTNER and Index to SYS (tried running the above
queries under SYS user also but still did not work) ?? If so how
can I grant access on an Index to PARTNER from SYS ??
Your help would be greatly appreciated.
Thanks in advance,
Cheers
Rashmi
null<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Rashmi Rungta ([email protected]):
Hi,
I have a table with huge amount of data and hence I have created
a function-based (Upper) index on one of the character NOT
NULL field which is very likely to be used for query purposes.
First of all though I can create ordinary normal field based
indexes in my user I cannot create a function-based index, why
That had to be created thru SYS user. Secondly I my query
invloving this function is not using the index and instead doing
a full-table scan. Problem outlined below :
Table : PLZPOST, USER / OWNER : PARTNER, FIELD : ORT
INDEX created on UPPER(ORT) in SYS user -
Create index upper_plz_ort on partner.plzpost (upper(ort))
When I give any of the following queries instead of using the
resp. index as mentioned in Oracle DOC it just does a full table
scan (checked thru Explain Plan) :
select * from PLZPOST where upper(ort) is not null;
select * from PLZPOST where upper(ort) like upper('saar%')
select * from PLZPOST where upper(ort) = 'SAARBRUECKEN'
etc etc
If anyone has used Function-based indexes in Oracle 8i could you
please tell me where am I going wrong. Is it because my Table
belongs to PARTNER and Index to SYS (tried running the above
queries under SYS user also but still did not work) ?? If so how
can I grant access on an Index to PARTNER from SYS ??
Your help would be greatly appreciated.
Thanks in advance,
Cheers
Rashmi<HR></BLOCKQUOTE>
null -
How can I enable function-based indexes on a already created
database. Is an Installation/Db Creation setting?
On another database I am able to create function-based indexes.
Any help appreciated.
Ashish
null<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Rashmi Rungta ([email protected]):
Hi,
I have a table with huge amount of data and hence I have created
a function-based (Upper) index on one of the character NOT
NULL field which is very likely to be used for query purposes.
First of all though I can create ordinary normal field based
indexes in my user I cannot create a function-based index, why
That had to be created thru SYS user. Secondly I my query
invloving this function is not using the index and instead doing
a full-table scan. Problem outlined below :
Table : PLZPOST, USER / OWNER : PARTNER, FIELD : ORT
INDEX created on UPPER(ORT) in SYS user -
Create index upper_plz_ort on partner.plzpost (upper(ort))
When I give any of the following queries instead of using the
resp. index as mentioned in Oracle DOC it just does a full table
scan (checked thru Explain Plan) :
select * from PLZPOST where upper(ort) is not null;
select * from PLZPOST where upper(ort) like upper('saar%')
select * from PLZPOST where upper(ort) = 'SAARBRUECKEN'
etc etc
If anyone has used Function-based indexes in Oracle 8i could you
please tell me where am I going wrong. Is it because my Table
belongs to PARTNER and Index to SYS (tried running the above
queries under SYS user also but still did not work) ?? If so how
can I grant access on an Index to PARTNER from SYS ??
Your help would be greatly appreciated.
Thanks in advance,
Cheers
Rashmi<HR></BLOCKQUOTE>
null -
Hi
I would like to know if it is possible to create a function based bitmap index?
ThanksI don't know whether you can or not, but if I needed to know, I would do something like this:
SQL> CREATE TABLE t (id NUMBER, gender NUMBER, name VARCHAR2(10));
Table created.
SQL> CREATE BITMAP INDEX t_gender ON
2 t (DECODE(gender, 1, 'M', 2, 'F', 'U'));
Index created.So, it appears that you can.
John -
Problem using two function based indexes at once!
Hello Oracle!
I've got problems using two function based indexes on geometries at once.
The problem occures, when I use a spatial join between two geometries both using function based indexes.
The test case:
CREATE TABLE quad (centroid NUMBER);
CREATE TABLE points (no NUMBER, point MDSYS.SDO_GEOMETRY);
CREATE OR REPLACE FUNCTION getQuad (centroid NUMBER) RETURN MDSYS.SDO_GEOMETRY DETERMINISTIC IS
BEGIN
RETURN MDSYS.SDO_GEOMETRY(2003, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1),MDSYS.SDO_ORDINATE_ARRAY(centroid-5,centroid-5,centroid+5,centroid-5,centroid+5,centroid+5,centroid-5,centroid+5,centroid-5,centroid-5));
END;
INSERT INTO USER_SDO_GEOM_METADATA VALUES('quad','tiedge.getQuad(centroid)',MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X', -100, 100, .0000001), MDSYS.SDO_DIM_ELEMENT('Y', -100, 100, .0000001)),NULL);
CREATE INDEX quad_idx on quad(getQuad(centroid)) INDEXTYPE IS MDSYS.SPATIAL_INDEX;
INSERT INTO quad VALUES (0);
INSERT INTO quad VALUES (5);
INSERT INTO quad VALUES (10);
INSERT INTO points VALUES (1, MDSYS.SDO_GEOMETRY(1001,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1,1),MDSYS.SDO_ORDINATE_ARRAY(4,4)));
ALTER SESSION SET QUERY_REWRITE_INTEGRITY=TRUSTED;
ALTER SESSION SET QUERY_REWRITE_ENA[i]Long postings are being truncated to ~1 kB at this time.hi there,
For a better audience for this question, I'd look at the database forum.
guys on that will be a lot more familiar with FBIs
thanks
Barry -
Hi
I am trying to create function based indexes based on the examples in the b10826 Spatial Users guide --
The Create index statement is failing because it says it cannot read the metadata
create index EMITTER_LOB_WIDX ON EMITTER (OWNER1.WT_GEOMETRY_PACKAGE.LINEOFBEARING(EQUIP_X, EQUIP_Y, LOB_BEARING, LOB_RANGE)) INDEXTYPE IS MDSYS.SPATIAL_INDEX LOCAL;
create index EMITTER_LOB_WIDX ON EMITTER (EMITTER.WT_GEOMETRY_PACKAGE.LINEOFBEARING(EQUIP_X, EQUIP_Y, LOB_BEARING, LOB_RANGE)) INDEXTYPE IS MDSYS.SPATIAL_INDEX LOCAL
ERROR at line 1:
ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
ORA-13203: failed to read USER_SDO_GEOM_METADATA view
ORA-13203: failed to read USER_SDO_GEOM_METADATA view
ORA-06512: at "MDSYS.SDO_INDEX_METHOD_10I", line 10
Here is the USER_SDO_GEOM_METADATA ENTRY:
TABLE_NAME
COLUMN_NAME
DIMINFO(SDO_DIMNAME, SDO_LB, SDO_UB, SDO_TOLERANCE)
SRID
EMITTER
OWNER1.WT_GEOMETRY_PACKAGE.LINEOFBEARING(EQUIP_X, EQUIP_Y, LOB_BEARING,
LOB_RANGE)
SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', -180, 180, .00005), SDO_DIM_ELEMENT('Y', -90,
90, .000005))
TABLE_NAME
COLUMN_NAME
DIMINFO(SDO_DIMNAME, SDO_LB, SDO_UB, SDO_TOLERANCE)
SRID
8307
The package is owned by OWNER1 - the Table is in OWNER2's schema - not that that matters - what are the known issues with Function Based Indexes
Am I missing something Obvious?I think its a bug
I moved the function to the local schema - I also pulled it out of the package -
So I look in USER_SDO_GEOM_METADATA no records for select * from USER_SDO_GEOM_METADATA
Not being satisfied with that I look in ALL_SDO_GEOM_METADATA
SELECT * FROM ALL_SDO_GEOM_METADATA WHERE OWNER = 'OWNER2';
no rows selected
So I should be good for insert
INSERT INTO USER_SDO_GEOM_METADATA VALUES ('EMITTER','OWNER2.EQUIPMENTPOINT(EQUIP_X, EQUIP_Y)', MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',-180,180,0.005),MDSYS.SDO_DIM_ELEMENT('Y',-90,90,0.005)), 8307);
INSERT INTO USER_SDO_GEOM_METADATA VALUES ('EMITTER','LOCUST2.EQUIPMENTPOINT(EQUIP_X, EQUIP_Y)', MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',-180,180,0.005),MDSYS.SDO_DIM_ELEMENT('Y',-90,90,0.005)), 8307)
ERROR at line 1:
ORA-13223: duplicate entry for EMITTER.OWNER2.EQUIPMENTPOINT(EQUIP_X, EQUIP_Y)
in SDO_GEOM_METADATA
ORA-06512: at "MDSYS.MD", line 1723
ORA-06512: at "MDSYS.MDERR", line 17
ORA-06512: at "MDSYS.SDO_GEOM_TRIG_INS1", line 21
ORA-04088: error during execution of trigger 'MDSYS.SDO_GEOM_TRIG_INS1'
If I insert to all_sdo_geom_metadata it takes but the index create fails b/c it cannot read user_sdo_geom_metadata
INSERT INTO ALL_SDO_GEOM_METADATA VALUES (OWNER2','EMITTER','OWNER2.EQUIPMENTPOINT(EQUIP_X, EQUIP_Y)', MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',-180,180,0.005),MDSYS.SDO_DIM_ELEMENT('Y',-90,90,0.005)), 8307);
1 row created.
SQL> CREATE INDEX EMITTER_EQUIP_WIDX ON EMITTER(OWNER2.EQUIPMENTPOINT(EQUIP_X, EQUIP_Y)) INDEXTYPE IS MDSYS.SPATIAL_INDEX PARAMETERS ('layer_gtype=point tablespace=EMITTER_IDX_TBS');
CREATE INDEX EMITTER_EQUIP_WIDX ON EMITTER(OWNER2.EQUIPMENTPOINT(EQUIP_X, EQUIP_Y)) INDEXTYPE IS MDSYS.SPATIAL_INDEX PARAMETERS ('layer_gtype=point tablespace=EMITTER_IDX_TBS')
ERROR at line 1:
ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
ORA-13203: failed to read USER_SDO_GEOM_METADATA view
ORA-13203: failed to read USER_SDO_GEOM_METADATA view
ORA-06512: at "MDSYS.SDO_INDEX_METHOD_10I", line 10
select table_name, column_name from user_sdo_geom_metadata;
TABLE_NAME
COLUMN_NAME
EMITTER
OWNER2.EQUIPMENTPOINT(EQUIP_X, EQUIP_Y)
Arghhh!!!
Anyone else encounter a similar problem?
I know that I have to be careful regarding owner.packager.function naming convention
I have followed the oracle examples from here
http://www.oracle.com/technology/obe/obe10gdb/content/spatial/files/add_metadata_fi.sql
are they broken? Is this a bug ? -
Function based indexes on object tables
Hi,
I am trying to create a function based index on an object table. I am getting the following error:
SQL> create index cell1_indx on cell1(create_cell1(id)) indextype is mdsys.spatial_index;
create index cell1_indx on cell1(create_cell1(id)) indextype is mdsys.spatial_index
ERROR at line 1:
ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
ORA-13249: internal error in Spatial index: [mdidxrbd]
ORA-13249: Error in Spatial index: index build failed
ORA-13249: Stmt-Execute Failure: SELECT num_rows from all_tables where owner='ASHE' and table_name=
'CELL1'
ORA-06512: at "MDSYS.SDO_INDEX_METHOD_9I", line 7
ORA-06512: at line 1
Here cell1 is an object table.
Is the procedure for creating function based indexes on object tables different from relational tables?
ChinniOne of the many new features in Oracle 8i is the Function-Based Index (we will refrain from using FBI, but only just). This allows the DBA to create indexes on functions or expressions; these functions can be user generated pl/sql functions, standard SQL functions (non-aggregate only) or even a C callout.
A classic problem the DBA faces in SQL Tuning is how to tune those queries that use function calls in the where clause, and result in indexes created on these columns not to be used.
Example
Standard B-Tree index on SURNAME with cost based optimizer
create index non_fbi on sale_contacts (surname);
analyze index non_fbi compute statistics;
analyze table sale_contacts compute statistics;
SELECT count(*) FROM sale_contacts
WHERE UPPER(surname) = 'ELLISON';
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=3 Card=1 Bytes=17)
1 0 SORT (AGGREGATE)
2 1 TABLE ACCESS (FULL) OF 'SALES_CONTACTS' (Cost=3 Card=16 Bytes=272)
Now we use a function based index
create index fbi on sale_contacts (UPPER(surname));
analyze index fbi compute statistics;
analyze table sale_contacts compute statistics;
SELECT count(*) FROM sale_contacts WHERE UPPER(surname) = 'ELLISON';
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=17)
1 0 SORT (AGGREGATE)
2 1 INDEX (RANGE SCAN) OF 'FBI' (NON-UNIQUE) (Cost=2 Card=381 Bytes=6477)
The function-based index has forced the optimizer to use index range scans (retuning zero or more rowids) on the surname column rather than doing a full table scan (non-index lookup). Optimal performance does vary depending on table size, uniqueness and selectivity of columns, use of fast full table scans etc. Therefore try both methods to gain optimal performance in your database.
It is important to remember that the function-based B*Tree index does not store the expression results in the index but uses an "expression tree". The optimizer performs expression matching by parsing the expression used in the SQL statement and comparing the results against the expression-tree values in the function-based index. This comparison IS case sensitive (ignores spaces) and therefore your function-based index expressions should match expressions used in the SQL statement where clauses.
Init.ora Parameters
The following parameter must be set in your parameter file: QUERY_REWRITE_INTEGRITY = TRUSTED
QUERY_REWRITE_ENABLED = TRUE
COMPATIBLE = 8.1.0.0.0 (or higher)
Grants
Grants To create function-based indexes the user must be granted CREATE INDEX and QUERY REWRITE, or alternatively be granted CREATE ANY INDEX and GLOBAL QUERY REWRITE. The index owner must have EXECUTE access on the function used for the index. If execute access is revoked then the function-based index will be "disabled" (see dba_indexes).
Disabled Indexes
If your function-based index has a status of "disabled" the DBA can do one of the following:
a) drop and create the index (take note of its current settings)
b) alter index enable, function-based indexes only, also use disable keyword as required
c) alter index unusable.
Queries on a DISABLED index fail if the optimizer chooses to use the index.Here is an example ORA error:
ERROR at line 1: ORA-30554: function-based index MYUSER.FBI is disabled.
All DML operations on a DISABLED index also fail unless the index is also marked UNUSABLE and the initialization parameter SKIP_UNUSABLE_INDEXES is set to true.
Some more Examples
CREATE INDEX expression_ndx
ON mytable ((mycola + mycolc) * mycolb);
SELECT mycolc FROM mytable
WHERE (mycola + mycolc) * mycolb <= 256;
..or a composite index..
CREATE INDEX example_ndx
ON myexample (mycola, UPPER(mycolb), mycolc);
SELECT mycolc FROM myexample
WHERE mycola = 55 AND UPPER(mycolb) = 'JONES';
Restriction & Rule Summary
The following restrictions apply to function based indexes. You may not index:
a) LOB columns
b) REF
c) Nested table column
d) Objects types with any of the above data types.
Function-based indexes must always follow these rules:
a) Cost Based optimizer only, must generate statistics after the index is created
b) Can not store NULL values (function can not return NULL under any circumstance)
c) If a user defined pl/sql routine is used for the function-based index, and is invalidated, the index will become "disabled"
d) Functions must be deterministic (always return the same value for a known input)
e) The index owner must have "execute" access on function used in the function-based index. Revocation of the privilege will render the index "disabled"
f) May have a B-Tree and Bitmap index type only
g) Can not use expressions that are based on aggregate functions, ie. SUM, AVG etc.
h) To alter a function-based index as enabled, the function used must be valid, deterministic and the signature of the function matches the signature of the function when it was created.
Joel P�rez -
Oracle 10g EE - Spatial Index, C Interfacing & Custom C Functions
Hi everyone,
I'm doing a research project concerning indexing and I'd like to do some testing using Oracle DB.
My questions are:
1) I've noticed here (http://www.oracle.com/database/product_editions.html) that Spatial is not included in EE, is this just the complex spatial functions? Is the R-tree (or some other spatial index) still available for simple queries?
2) I've read that Pro*C is the simplest way to use Oracle from C, however Pro*C does not exist in 10g, only OCI. Is there a simpler way to use Oracle from C other than OCI?
3) How do I go about creating custom functions which are written in C (for speed reasons)?
If not all of these are possible in EE, which version of Oracle would I need?
Thanks heaps,
Martin.From the binaries point of view Spatial is included in the Enterprise Edition, the fact that it says it is an option means you have to buy a license additional from the enterprise Edition license to be able to use it.
You can find several demos based on MapViewer which are written in java, so IMO Pro*C is not the best suitable way to start working with Spatial Data, I suggest you to consider Java instead.
~ Madrid
http://hrivera99.blogspot.com/ -
Error creating function based index
i keep getting ORA-13203 errors when creating a function-based index. The function is owned by another schema but the the user creating the function has execute privileges
[email protected]> create index mpp_nc_sidx on MPP_NONCOMPLETE(GIS.DD832UTM(LON*-1,LAT))
2 indextype is mdsys.spatial_index
3 parameters('tablespace=sde4_idx sdo_indx_dims=2');
create index mpp_nc_sidx on MPP_NONCOMPLETE(GIS.DD832UTM(LON*-1,LAT))
ERROR at line 1:
ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
ORA-13203: failed to read USER_SDO_GEOM_METADATA table
ORA-13203: failed to read USER_SDO_GEOM_METADATA table
ORA-06512: at "MDSYS.SDO_INDEX_METHOD_9I", line 7
ORA-06512: at line 1
[email protected]> select table_name,column_name from user_sdo_geom_metadata;
TABLE_NAME COLUMN_NAME
MPP_NONCOMPLETE GIS.DD832UTM(LON*-1,LAT)
[email protected]> select GIS.DD832UTM(LON*-1,LAT) from mpp_noncomplete where rownum < 3;
GIS.DD832UTM(LON*-1,LAT)(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
SDO_GEOMETRY(2001, 82212, SDO_POINT_TYPE(864941.804, 3916953.95, NULL), NULL, NULL)
SDO_GEOMETRY(2001, 82212, SDO_POINT_TYPE(568560.541, 4181497.56, NULL), NULL, NULL)
[email protected]> select text from all_source where name = 'DD832UTM';
TEXT
FUNCTION dd832utm(x number, y number)
RETURN mdsys.sdo_geometry DETERMINISTIC
IS
geom mdsys.sdo_geometry;
BEGIN
geom := sdo_cs.transform
(mdsys.sdo_geometry (2001,8265,mdsys.sdo_point_type
(x,y, null),null,null),82212);
return geom;
END;
any help appreciated
--kassimHi, try to use a view:
create or replace view v_dd832utm as
select
mdsys.sdo_geometry(2001,8265,
mdsys.sdo_point_type((LON*-1),LAT, null),null,null),
82212)as GEOMETRY
from
mpp_noncomplete;
provide metadata for that view (column: GEOMETRY) and create a spatial index. your way is more sophisticated ;o)
regards, Andreas -
Function-based index with OR in the wher-clause
We have some problems with functin-based indexes and
the or-condition in a where-clause.
--We use Oracle 8i (8.1.7)
create table TPERSON(ID number(10),NAME varchar2(20),...);
create index I_NORMAL_TPERSON_NAME on TPERSON(NAME);
create index I_FUNCTION_TPERSON_NAME on TPERSON(UPPER(NAME));
The following two statements run very fast on a large table
and the execution-plan asure the usage of the indexes
(-while the session is appropriate configured and the table is analyzed):
1) select count(ID) FROM TPERSON where upper(NAME) like 'MIL%';
2) select count(ID) from TPERSON where NAME like 'Mil%' or (3=5);
In particular we see that a normal index is used while the where-clause contains
an OR-CONDITION.
But if we try the similarly select-statement
3) select count(ID) FROM TPERSON where upper(NAME) like 'MIL%' or (3=5);
the CBO will not use the function-index I_FUNCTION_TPERSON_NAME and we have a full table scan in the execution-plan.
(This behavior we only expect with views but not with indexes.)
We ask for an advice like a hint, which enable the CBO-usage
of function-based indexes in connection with OR.
This problem seems to be artificial because it contains this dummy logic:
or (3=5).
This steams from an prepared statement, where this kind of boolean
flag reduce the amount of different select-statements needed for
covering the hole business-logic, while using bind-variables for the
concrete query-parameters.
A more realistic (still boild down) version of our select-statement is:
select * FROM TPERSON
where (upper(NAME) like 'MIL%' or (NAME is null))
and (upper(FIRSTNAME) like 'MICH% or (FIRSTNAME is null))
and ...;
thank you for time..
email: [email protected]In the realistic statement you write :
select * FROM TPERSON
where (upper(NAME) like 'MIL%' or (NAME is null))
and (upper(FIRSTNAME) like 'MICH% or (FIRSTNAME is null))
and ...;
as far as i know, NULL values are not indexed, "or (NAME is NULL)" have to generate a full table scan.
HTH
We have some problems with functin-based indexes and
the or-condition in a where-clause.
--We use Oracle 8i (8.1.7)
create table TPERSON(ID number(10),NAME varchar2(20),...);
create index I_NORMAL_TPERSON_NAME on TPERSON(NAME);
create index I_FUNCTION_TPERSON_NAME on TPERSON(UPPER(NAME));
The following two statements run very fast on a large table
and the execution-plan asure the usage of the indexes
(-while the session is appropriate configured and the table is analyzed):
1) select count(ID) FROM TPERSON where upper(NAME) like 'MIL%';
2) select count(ID) from TPERSON where NAME like 'Mil%' or (3=5);
In particular we see that a normal index is used while the where-clause contains
an OR-CONDITION.
But if we try the similarly select-statement
3) select count(ID) FROM TPERSON where upper(NAME) like 'MIL%' or (3=5);
the CBO will not use the function-index I_FUNCTION_TPERSON_NAME and we have a full table scan in the execution-plan.
(This behavior we only expect with views but not with indexes.)
We ask for an advice like a hint, which enable the CBO-usage
of function-based indexes in connection with OR.
This problem seems to be artificial because it contains this dummy logic:
or (3=5).
This steams from an prepared statement, where this kind of boolean
flag reduce the amount of different select-statements needed for
covering the hole business-logic, while using bind-variables for the
concrete query-parameters.
A more realistic (still boild down) version of our select-statement is:
select * FROM TPERSON
where (upper(NAME) like 'MIL%' or (NAME is null))
and (upper(FIRSTNAME) like 'MICH% or (FIRSTNAME is null))
and ...;
thank you for time..
email: [email protected] -
Creation of function based index using escape
Hello,
I have the following SQL, sometimes performing bad:
SELECT DISTINCT UPPER(A.PROCESSIDCODE), UPPER(A.RULENAME), CHARSET
FROM XIB_DETECT A, XIB_PROCESSIDPROPERTIES B, XIB_RULES C
WHERE ( A.KEY1 = :P1 OR ( :P1 like REPLACE(REPLACE(REPLACE(REPLACE(KEY1,'%', '\%'),'_', '\_'),'?', '_'),'*','%') escape '\' AND A.REGFLAGS1 = 'Y') OR A.KEY1 = '*' AND A.REGFLAGS1 = 'Y')
AND (A.KEY2 = :P2 OR ( :P2 like REPLACE(REPLACE(REPLACE(REPLACE(KEY2,'%', '\%'),'_', '\_'),'?', '_'),'*','%') escape '\' AND A.REGFLAGS2 = 'Y') OR (A.KEY2 IS NULL AND A.REGFLAGS2 IS NULL ) )
AND (A.KEY3 = :P3 OR ( :P3 like REPLACE(REPLACE(REPLACE(REPLACE(KEY3,'%', '\%'),'_', '\_'),'?', '_'),'*','%') escape '\' AND A.REGFLAGS3 = 'Y') OR (A.KEY3 IS NULL AND A.REGFLAGS3 IS NULL ) )
AND (A.KEY4 = :P4 OR ( :P4 like REPLACE(REPLACE(REPLACE(REPLACE(KEY4,'%', '\%'),'_', '\_'),'?', '_'),'*','%') escape '\' AND A.REGFLAGS4 = 'Y') OR (A.KEY4 IS NULL AND A.REGFLAGS4 IS NULL ) )
AND (A.KEY5 = :P5 OR ( :P5 like REPLACE(REPLACE(REPLACE(REPLACE(KEY5,'%', '\%'),'_', '\_'),'?', '_'),'*','%') escape '\' AND A.REGFLAGS5 = 'Y') OR (A.KEY5 IS NULL AND A.REGFLAGS5 IS NULL ) )
AND (A.KEY6 IS NULL OR A.KEY6 = '*' AND REGFLAGS6 = 'Y')
AND (A.KEY7 IS NULL OR A.KEY7 = '*' AND REGFLAGS7 = 'Y')
AND (A.KEY8 IS NULL OR A.KEY8 = '*' AND REGFLAGS8 = 'Y')
AND (A.KEY9 IS NULL OR A.KEY9 = '*' AND REGFLAGS9 = 'Y')
AND (A.KEY10 IS NULL OR A.KEY10 = '*' AND REGFLAGS10 = 'Y')
AND ( ( A.PROCESSIDCODE IS NOT NULL AND UPPER(A.PROCESSIDCODE) = UPPER(B.PROCESSIDCODE) AND A.XLEVEL = B.XLEVEL AND B.ACTIVEFLAG = 'Y' )
OR ( A.RULENAME IS NOT NULL AND UPPER(A.RULENAME) = UPPER(C.RULENAME) AND A.XLEVEL = C.XLEVEL AND C.ACTIVEFLAG = 'Y' ) );
Now I want to create a function based index on the key1 column:
CREATE INDEX xib_detect_ix ON xib_detect (REPLACE(REPLACE(REPLACE(REPLACE(KEY1,'%', '\%'),'_', '\_'),'?', '_'),'*','%') escape '\') TABLESPACE ... ONLINE;
However, this is not working with "escape" '\', throwing: ORA-00907: missing right parenthesis
Any idea how to create an index on this construct with "escape"?
Database version is 10.2.0.3.
Thanks a lot.
Regards
OliverHi,
You can get the "missing right parenthesis" error for many different syntax errors.
In this case, you really are missing a right parenthesis. Your statement has 5 left '('s, but only 4 right ')'s. It's easy to see this if you format your code:
CREATE INDEX xib_detect_ix
ON xib_detect ( REPLACE ( REPLACE ( REPLACE ( REPLACE ( KEY1
escape '\'
ESCAPE is an option that you can use with the LIKE operator. It gives you a mechanism for cancelling the special meaning of symbols like '%'. You're not using the LIKE operator to create the index. You're only using REPLACE, and no characters have any special meaning in REPLACE, so there's no way (or reason) to escape them. Use ESCAPE in queries that use LIKE, when appropriate. -
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?...
Maybe you are looking for
-
Error F107:Restrict Period while running the report RFUMSV50
Hello Experts, I am facing the problem while runing the report RFUMSV50. I am running it first time and getting this error F107:Restrict Period Kindly guide me Regards Naveen
-
Compressor reloads entire MKV file every time I do anything!
I have a 4gb MKV movie that I am trying to convert using compressor. When I add it I have to wait for it to load the entire file... like 20 minutes. And every time I change a setting it has to reload the entire file before it lets me do anything else
-
Facebook and Twitter thumbnails on Safari doesn't working!!!!
Does anybody know why the thumbnails on Safari's top sites of facebook and twitter doesn't work?? I mean, when I open my Safari's top sites, i can see all my top sites with their respective pictures/thumbnails except for the facebook and twitter page
-
Getting error while reading the positional flat files
Hi, I have a requirement to read a Positional Flat file and convert into XML through oracle B2B. I have created a positional flat file .ecs, XSD and parser .ecs file using the blog http://anuj-dwivedi.blogspot.in/2011/10/handling-positionaldelimited-
-
E75 How to disable power save or light time out?
Hi, I want to disbale either the power save or change the light time out setting, but I can do neither? Can anyone assist? Thanks