Can a query make use of an Index on concat column ?
Hi sql gurus,
We will develope application on a database as below ( simplified ) :
create table invoice (doc_no varchar2(30), cust_code varchar2(10), amount number (12,2));
create table debit_memo (doc_code varchar2(6), doc_no varchar2(24), cust_code varchar2(10), amount number (12,2));
create table credit_memo (doc_code varchar2(6), doc_no varchar2(24), cust_code varchar2(10), amount number (12,2));
create view v_ar_transaction as
select doc_no, cust_code, amount from invoice
union
select doc_code||doc_no, cust_code, amount from debit_memo
union
select doc_code||doc_no, cust_code, amount from credit_memo
The question is :
If I have query like this :
select * from v_ar_transaction where doc_no = :pdoc_no
Can it use the index built on the tables ?
What kind of index that will help the above query to be efficient ?
Thank you for your help,
xtanto
create view v_ar_transaction as
select doc_no, cust_code, amount from invoice
union
select doc_code||doc_no, cust_code, amount from
debit_memo
union
select doc_code||doc_no, cust_code, amount from
credit_memo
he question is :
If I have query like this :
select * from v_ar_transaction where doc_no =
:pdoc_no
an it use the index built on the tables ?
What kind of index that will help the above query to
be efficient ?I'd try:
doc_no for invoice
function based index doc_code||doc_no for debit_memo and credit_memo
As a side note - do you really need UNION or UNION ALL?
Isn't important where the transaction comes from?
Gints Plivna
http://www.gplivna.eu
Similar Messages
-
How can I best make use of all my devices ? Mac mini, Apple TV, AirPort Extreme, airport express, ipad 2 (all purchased in 2011) and an old imac with OS X. I use my iPhones personal hotspot for all Internet.
Maybe you are looking to re-purpose this equipment versus getting rid of it if so, the best thing to do is search the internet for tutorials. And I say this because it's what I would do, there are a lot of tutorials online. Hope you can find good use for them. Worse case scenario if you can't find something right now, package them very nicely and when you come across something unbox and enjoy. I've re-purposed a mac color classic and LOVE IT!!
-
Trying to make use of bitmap indexes
Hello!
I have a table that contains about 16 mill rows and each night about
60.000-70.000 rows are proccessed against the table so that part of the rows
is updated and another part is inserted.
The table contains three IDEAL columns for bitmap indexes the first of which
may have only two, the second three and the third four distinct values.
I was planning to change the index type on these columns to BITMAP but
Oracle doesnt recommend to build BITMAP indexes on heavily updated or inserted
columns.
So the only use of bitmap indexes turns out to be read-only tables.
From the other hand a sloution might be dropping indexes before the load and rebuilding them after the load has completed what can lead to often tablespace fragmentations.
So, the question is how can I use bitmap indexes in a case like this one?
What are wayouts?
Thank you very mcuh for the reply.>
The table contains three IDEAL columns for bitmap indexes the first of which
may have only two, the second three and the third four distinct values.
Contrary to popular legend, and possibly contrary even to the manuals and Metalink, these columns are NOT necessarily ideal for bitmap indexes. Consider a query with:
col1 = '1_of_2'
and col2 = '1_of_3'
and col3 = '1_of_4'You have a total of 24 possible combinations. Given your 16M rows, this means that on average the optimizer will expect to collect about 670.000 rows spread across something like 100,000 to 130,000 blocks. Under these circumstances you may find that Oracle doesn't use the indexes anyway (unless you fool it by fiddling with parameters like the optimizer_index_cost_adj, and that's generally a bad idea) - and if the model is a reasonable description of the actual data it probably shouldn't use the indexes.
There are various special circumstance that might make the indexes effective for querying, though. (Note - at this point I'm not considering the impact on inserts, updates and deletes). The most obvious example is where all three columns each have at least one very repetitive value and all your queries are trying to find data for the remaining "rare" values. If this is the case then you need to index the columns and collect histograms on the columns so that the optimiser can model the data correctly; and then you may also need to modify your SQL to ensure that your queries against these columns always use literal values, not bind variables.
If some of your queries are supposed to return small amounts of data, there are various mechanisms you could use to do this efficiently. If your queries are always going to return large amounts of data, then there are other strategies that are likely to be more appropriate.
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk -
Can Illustrator really make use of 8GB RAM?
Hello,
I'm thinking of upgrading my 17" 2010 Core i7 Macbook Pro from the curretn 4GB of RAM to 8GB or RAM as the prices have come down considerably. (around £40.00).
I've already posted a thread on a mac forum, but I thought that posting in on here would also be benificial.
Basically I would like to know is, is there any point doubling the RAM? Can Illustrator realy utilise 8GB of RAM? My files are becoming larger and so Illustrator runs slower - I've monitered this in Activity monitor and the pages in/out seem to have a 10% difference which is apparantley a indication of more RAM needed. I've also seen a few 'Not enough memory' messages in Illustrator.
Thanks for your input.
NathanIllustrator on the Mac is a 32Bit app currently. It can only utilize ~3GB of RAM. Hopefully, since Illustrator is one of the last remaining non-64Bit Adobe apps, that'll change in the near future. If you are buying for performance today.. it won't make any differnce. If you are buying for performance next year or 6 months from now, it may make a world of differnce.
You can still launch and use Illustrator on a 64bit system (I do every day) but it won't see any additional RAM. That does not mean more RAM isn't helpful. Illustrator can use it's ~3GB and the OS cna utilise the rest. This does make things faster even if Illustrator is still limited. In addition, I don't know any Mac users that use Illustrator and do not use Photoshop. Photoshop is a 64bit app and will use as much RAM as you feed it. -
Can BPEL/ESB make use of B2B Callouts?
Hi
Consider we use BPEL/ESB between Oracle XML Gateway and Oracle B2B. Can we make use of B2B callout feature in this scenario? If yes, could anyone brief how to achieve it?
Regards
Prasad JayakumarHi Ramesh
Your response clarified my original question. Thank you.
Now I have couple of questions considering the following architecture
APPS (XML Gateway) <-> BPEL/ESB <-> B2B
Please respond for benefit of all B2B users
1. Lets say we have few trading partners who expect Invoice in RosettaNet format and few others expect Invoice in EDI format.
a. How to achieve it?
b. Should BPEL/ESB based upon some condition choose the right B2B Web Service and do transformation and send the data?.
2. What's the major role played by B2B? How different B2B is, in handling transactions directly from XML Gateway and/or through BPEL/ESB?
Regards
Prasad Jayakumar -
How to make use of the index in my manual within Acrobat
I've created an index in my FrameMaker book and would like it to be of use when it's converted to PDF.
An index is most useful if it's provided in hard copy. How can I make it useful in Acrobat?
Do I do something within Frame or Acrobat or both?
Also, when I convert my document to PDF with bookmarks, a bookmark does not appear for my index.
I have Acrobat 9 Pro.
Thank you!In the book file, right-click the index file and select Set up Standard Index. In the subsequent dialog box, select Create Hypertext Links. Click Set. Update the book.
When you print the book, click PDF Setup. In the Links tab, select Create Named Destinations for All Elements and Paragraphs.
To make the Index appear in the bookmarks, check that its paragraph format style is included in the Include paragraphs list in the PDF setup dialog box.
Hope this helps,
Van -
Can I query WMI using Data Collection Form ZCM 11 Sp2
I'm very new to ZenWorks and I'm trying to query WMI from the Data Collection Form in an admin defined field.
I read somewhere that you can query WMI in a similar fashion to querying a registry key but not getting results.
Any help would really be appreciated.
Thanks.robmetcalfe,
It appears that in the past few days you have not received a response to your
posting. That concerns us, and has triggered this automated reply.
Has your problem been resolved? If not, you might try one of the following options:
- Visit http://support.novell.com and search the knowledgebase and/or check all
the other self support options and support programs available.
- You could also try posting your message again. Make sure it is posted in the
correct newsgroup. (http://forums.novell.com)
Be sure to read the forum FAQ about what to expect in the way of responses:
http://forums.novell.com/faq.php
If this is a reply to a duplicate posting, please ignore and accept our apologies
and rest assured we will issue a stern reprimand to our posting bot.
Good luck!
Your Novell Product Support Forums Team
http://forums.novell.com/ -
Can following query be used to find inserted update records.
hi,
i am using query1) to insert data query2) to update the record
query1)
INSERT INTO [t1]
( id
,createddatetime
,updateddatetime)
VALUES
(1
,GETDATE()
,GETDATE())
query2)
update t1 set updatedatetime=getdate() where id=@t1
please tel me will two date cols get same time , that is, will i be able to
write following to find inserted/updated rows
if exists(select * from t1 where createddt1=updateddt2)
begin
select 'inserted'
end
else
begin
select 'updated'
end
yours sincerelyDepending on how you execute both the queries there's a small chance date value comparison may not wok as expected as datetime also has timepart until milliseconds precision. So if you want to retrieve details on records inserted and updated you may use
something like below
query 1
DECLARE @dt datetime
SET @dt = GETDATE()
INSERT INTO [t1]
( id
,createddatetime
,updateddatetime)
VALUES
(1
,@dt
,@dt)
query2
DECLARE @dt datetime
SET @dt = GETDATE()
update t1 set updatedatetime=@dt where id=@t1
then you can do below to get inserted updated detailsif exists(select * from t1 where createddt1=updateddt2)begin select 'inserted'end elsebegin select 'updated'end
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Can Premier Pro make use of caption and keyword metadata from Lightroom
I’m using Premier CS6 to create a slideshow with images from Lightroom. When I export from Lightroom, I have quite a bit of Metadata encoded into the image and I’m wondering if there is a way to see that metadata in Premier?
I’m probably dreaming but I’d love to be able to create a lower third, title template that would get its information from the Caption field in Lightroom.
Any other tips for using Lightroom and Premier together would be appreciated.Whatever metadata is viewable in PP will be available in the metadata pane. However, titles cannot automatically 'grab' their data from any source. It has to be typed or copied in manually.
-
Want to query a set of unique values for concat columns
Hi,
I have Table1 with unique constraint on col2 and col3.
Have to optimize the following query as it does a FTS
select * from table1
where col2||col3 in (col1val1 || col2val1, col1val2 || col2val2, ....)
Please advise, Thanks In Advance.select * from table1
where col2||col3 in (col1val1 || col2val1, col1val2
|| col2val2, ....)How about
select * from table1
where col2, col3 in (select col1val1, col2val1 from dual union all
select col1val2, col2val2 from dual union all...
) -
Using a Value index on XMLIndex path table.
I am trying to understand how to capitalize on the VALUE index created on a XMLIndex path table. So far, I have not been able to successfully use it. I am not sure whether I am misunderstanding the way it is intended to be used? Or am making a mistake somewhere else along the way. Here is a use-case where I think that it should be getting picked up by the optimizer:
CREATE TABLE TEST_TABLE
(ID VARCHAR2(128) NOT NULL,
XML_DATA XMLTYPE NOT NULL,
CONSTRAINT TEST_PK PRIMARY KEY (ID))
XMLTYPE COLUMN XML_DATA STORE AS BINARY XML;
-- Populate the table with some random data. Here, our single attribute should be
-- unique for each row.
INSERT INTO TEST_TABLE (
SELECT dbms_random.string('A', 15), XMLElement("Test", XMLAttributes(dbms_random.string('A', 15) as "someAttr"))
FROM DUAL
CONNECT BY LEVEL <= 20000 );
CREATE INDEX test_xmlindex_ix ON TEST_TABLE(XML_DATA) INDEXTYPE IS XDB.XMLIndex
PARAMETERS('
PATHS (Include (/Test/@someAttr))
PATH TABLE test_path_table
PATH ID INDEX test_path_id_ix
ORDER KEY INDEX test_key_ix
VALUE INDEX test_value_ix ');
-- Not sure if I need these or not?
CALL DBMS_STATS.GATHER_TABLE_STATS ('MYSCHEMA', 'TEST_TABLE');
CALL DBMS_STATS.GATHER_TABLE_STATS ('MYSCHEMA, 'TEST_PATH_TABLE');
-- Now, I would expect this query to use the Value index that was created.
-- Instead, the Explain plan indicates that TEST_PATH_ID_IX was used..
SELECT xml_data
FROM test_table v
WHERE extractValue(v.xml_data, '/Test/@someAttr') = ?
Here are the operations listed in the explain plan for the query:
SELECT STATEMENT
FILTER
TABLE ACCESS(FULL) MYSCHEMA.TEST_TABLE
TABLE ACCESS(BY INDEX ROWID) MYSCHEMA.TEST_PATH_TABLE
INDEX(RANGE SCAN) MYSCHEMA.TEST_PATH_ID_IXIf I understand everything correctly, here, there is no reason why the PATH ID index should have been used. Isn't this index strictly for the XML tags themselves? Why wouldn't it use the Value index?
Thanks,
JonPATH_TABLE
+=======================================================+
| PathID | RID | Order_Key | Locator | Value |
|-------------------------------------------------------|
| RAW | rowid | RAW | RAW | varchar2(4000) |
|-------------------------------------------------------|
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
+=======================================================+
XMLIndex
1) PATH INDEX: (PathID, RID) - BTree
2) ORDER INDEX: (RID, ORDER_KEY) - BTree
3) VALUE INDEX: (substr("VALUE",1,1599)) - Function Based
Locator: Pointer to XML Fragments
XMLIndex - Namespace issue...
I believe that (although I don't know the exact mechanics) that it will use the path index first to find the needed
tree node / path, then will look for a locator that matches the request and if not will do an full table scan
afterwards, if not successful, trying to limit the request with the filter at hand, so see if it can be used, to
minimize the sub-results.
Message was edited by:
Marco Gralike -
Hi,
I want to use a text based index. The problem statement was i have to delete all those records which have column
'ABC%'
means data can be ABC1, ABC2, ABCl, ABCn
so i thought i would do like
delete from tab1
where col1 like 'ABC%'.
There are millions of records.
so i thought of optimizing the Query by using text based index. If my approach is right can you suggest how i can implement it and Is there any other way around?
Thanks
_vinodAre you saying that simple b tree index would be used in a qurey where i have used LIKE operator? Yes. Not "would" but certainly "could", as long as wildcard is trailing.
Now whether it "would" depends on whether it's estimated to be the cheapest access path. -
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 -
Qeury not using the bitmap index
Hi,
Pls have a look at the query below:
SELECT
A.flnumber,
A.fldate,
SUBSTR(C.sec,1,3) sect,
D.element,
C.class,
SUM(C.qty) qty,
A.indicator,
DECODE(A.indicator, 'I', B.inrt, 'O', B.outrt, 'R', B.rting, NULL) direction,
B.rting
FROM
Header A,
Paths B,
PathData C,
ElementData D
WHERE
(D.category='N') AND
(A.rt=B.rt) AND
(C.element=D.element) AND
(A.fldate=C.fldate AND
A.flnumber=C.flnumber) AND
C.element IN (SELECT codes FROM Master_codes WHERE type='F')
GROUP BY A.flnumber,
A.fldate,
SUBSTR(C.sec, 1, 3),
D.element,
C.class,
A.indicator,
DECODE(A.indicator,'I', B.inrt, 'O', B.outrt,'R', B.rting, NULL),
B.rting
UNION ALL
SELECT
A.flnumber,
A.fldate,
SUBSTR(C.sec,1,3) sect,
D.element,
C.class,
SUM(C.qty) qty,
A.indicator,
DECODE(A.indicator, 'I', B.inrt, 'O', B.outrt, 'R', B.rting, NULL) ROUTE_direction,
B.rting
FROM
Header A,
Paths B,
PathData C,
ElementData D
WHERE
(D.category='N') AND
(A.rt=B.rt) AND
(C.element=D.element) AND
(A.fldate=C.fldate AND
A.flnumber=C.flnumber) AND
C.element NOT IN (SELECT codes FROM Master_codes WHERE type='F')
GROUP BY A.flnumber,
A.fldate,
SUBSTR(C.sec, 1, 3),
D.element,
C.class,
A.indicator,
DECODE(A.indicator,'I', B.inrt, 'O', B.outrt,'R', B.rting, NULL),
B.rting
The cost in the explain plan is very high. The table PathData* has 42710366 records and there is a bitmap index on the flnumber_ and fldate* columns. But the query above does not use the indexes. The other tables in the list are fine as their respective PK and indexes are used but the table PathData* is going for a "Table Access by Local Index Rowid". dont know what it means but the cost for this is 7126 which is high. I cant figure out why is the query not using the bitmap indexes for this table.
Pls let me know what should be done.???Thread: HOW TO: Post a SQL statement tuning request - template posting
HOW TO: Post a SQL statement tuning request - template posting
SELECT a.flnumber,
a.fldate,
Substr(c.sec, 1, 3) sect,
d.element,
c.class,
SUM(c.qty) qty,
a.INDICATOR,
Decode(a.INDICATOR, 'I', b.inrt,
'O', b.outrt,
'R', b.rting,
NULL) direction,
b.rting
FROM header a,
paths b,
pathdata c,
elementdata d
WHERE ( d.category = 'N' )
AND ( a.rt = b.rt )
AND ( c.element = d.element )
AND ( a.fldate = c.fldate
AND a.flnumber = c.flnumber )
AND c.element IN (SELECT codes
FROM master_codes
WHERE TYPE = 'F')
GROUP BY a.flnumber,
a.fldate,
Substr(c.sec, 1, 3),
d.element,
c.class,
a.INDICATOR,
Decode(a.INDICATOR, 'I', b.inrt,
'O', b.outrt,
'R', b.rting,
NULL),
b.rting
UNION ALL
SELECT a.flnumber,
a.fldate,
Substr(c.sec, 1, 3) sect,
d.element,
c.class,
SUM(c.qty) qty,
a.INDICATOR,
Decode(a.INDICATOR, 'I', b.inrt,
'O', b.outrt,
'R', b.rting,
NULL) route_direction,
b.rting
FROM header a,
paths b,
pathdata c,
elementdata d
WHERE ( d.category = 'N' )
AND ( a.rt = b.rt )
AND ( c.element = d.element )
AND ( a.fldate = c.fldate
AND a.flnumber = c.flnumber )
AND c.element NOT IN (SELECT codes
FROM master_codes
WHERE TYPE = 'F')
GROUP BY a.flnumber,
a.fldate,
Substr(c.sec, 1, 3),
d.element,
c.class,
a.INDICATOR,
Decode(a.INDICATOR, 'I', b.inrt,
'O', b.outrt,
'R', b.rting,
NULL),
b.rting Edited by: sb92075 on Mar 13, 2011 7:58 AM -
Can I refactor this query to use an index more efficiently?
I have a members table with fields such as id, last name, first name, address, join date, etc.
I have a unique index defined on (last_name, join_date, id).
This query will use the index for a range scan, no sort required since the index will be in order for that range ('Smith'):
SELECT members.*
FROM members
WHERE last_name = 'Smith'
ORDER BY joindate, idIs there any way I can get something like the following to use the index (with no sort) as well:
SELECT members.*
FROM members
WHERE last_name like 'S%'
ORDER BY joindate, idI understand the difficulty is probably; even if it does a range scan on every last name 'S%' (assuming it can?), they're not necessarily in order. Case in point:
Last_Name: JoinDate:
Smith 2/5/2010
Smuckers 1/10/2010An index range scan of 'S%' would return them in the above order, which is not ordered by joindate.
So is there any way I can refactor this (query or index) such that the index can be range scanned (using LIKE 'x%') and return rows in the correct order without performing a sort? Or is that simply not possible?xaeryan wrote:
I have a members table with fields such as id, last name, first name, address, join date, etc.
I have a unique index defined on (last_name, join_date, id).
This query will use the index for a range scan, no sort required since the index will be in order for that range ('Smith'):
SELECT members.*
FROM members
WHERE last_name = 'Smith'
ORDER BY joindate, idIs there any way I can get something like the following to use the index (with no sort) as well:
SELECT members.*
FROM members
WHERE last_name like 'S%'
ORDER BY joindate, idI understand the difficulty is probably; even if it does a range scan on every last name 'S%' (assuming it can?), they're not necessarily in order. Case in point:
Last_Name: JoinDate:
Smith 2/5/2010
Smuckers 1/10/2010An index range scan of 'S%' would return them in the above order, which is not ordered by joindate.
So is there any way I can refactor this (query or index) such that the index can be range scanned (using LIKE 'x%') and return rows in the correct order without performing a sort? Or is that simply not possible?Come on. Index column order does matter. "LIKE 'x%'" actually is full table scan. The db engine accesses contiguous index entries and then uses the ROWID values in the index to retrieve the table rows.
Maybe you are looking for
-
How to get distinct values in a comma separated list of email addresses?
Hi Friends, I have a cursor which fetches email address along with some other columns. More than one record can have same email address. Ex CURSOR C1 IS SELECT 1 Buyer,'XX123' PO, '[email protected]' Buyer_email from dual UNION ALL SELECT 2 Buyer,'XX
-
Cd insert prints jumbled artist/song. Same as in 11.0 in new 11.02
CD Insert Jumbled Printout. I just downloaded 11.02. I went to printout a cd insert and the artist names and songs are all jumbled. This also happened when 11.0 was first downloaded and 11.01 fixed it.
-
What is the autocreated file "profiles.bin"?
I just discovered a file in my home folder named "profiles.bin", with a creation date of 1/14/08. I checked my daughter's computer, and she has the same file with the same creation date in her home folder. Anyone know what this is??
-
Problem while applying configuration to SCE 8000 using SCE-API
We are facing an issue while applying service configuration to SCE 8000 device using SCE API supplied by CISCO. We have sample .pqb file which we are using to upload to SCE 8000. We are using 3.5.5 version of firmware on SCE. Attached is exception
-
I have problems installing "perfect man"
I have problems installing "perfect man" - it downloads but won't install. Anyone else find this?