 |
|
 |
|
Next: Urgent requirement in Oracle
|
| Author |
Message |
External

Since: Jan 14, 2008 Posts: 65
|
(Msg. 1) Posted: Wed Oct 01, 2008 5:39 pm
Post subject: Walking a CLOB Archived from groups: comp>databases>ibm-db2 (more info?)
|
|
|
Friends:
I'm in the unenviable position of having to retrieve rows based on a
deep-dive into a CLOB, searching for a particular constant.
I've tried different options of predicates and their placement, and
listed below--in the order of best cost to worst--are the ones I've
tried:
1. LIKE predicate, e.g., CLOB_FIELD LIKE '%characterstring%' in the
WHERE clause
2. LOCATE predicate, e.g., LOCATE('characterstring', CLOB_FIELD) > 0
in the WHERE clause
3. POSSTR predicate, e.g., POSSTR (CLOB_FIELD, 'characterstring') > 0
in the WHERE clause
4. Same as 1, but in a CASE statement in the SELECT clause, e.g. CASE
WHEN CLOB_FIELD LIKE...
5. Same as 2, but in a CASE statement in the SELECT clause, e.g. CASE
WHEN 0 < LOCATE...
6. Same as 3, but in a CASE statement in the SELECT clause, e.g., CASE
WHEN 0 < POSSTR...
Let me add that the table with the CLOB is also being joined-to, and,
as one might expect, it doesn't matter if I move predicates 1-3 from
the WHERE to the ON clause.
Finally, note that my platform is DB2 8.2 LUW on AIX 5.2, so I don't
have the relevant XML functions in 9.x available to me.
My question is this: focusing just on queries 1 and 4, despite what
the EXPLAIN tells me, the query with the LIKE in a CASE statement in
the SELECT clause is executing much faster than the one with the LIKE
in the WHERE. In other words, 4 costs more than 1, but performs
considerably better.
Why might this be? Is there an optimizer-level difference in the way
predicates are handled in the WHERE clause versus the SELECT clause?
Another wrinkle is that CLOBs are "handled" outside of the buffer
cache, so looking under the hood only shows so much. Feel free also to
let me know if there's another v8-compatible CLOB-crawling technique
I'm overlooking.
Thanks,
--Jeff >> Stay informed about: Walking a CLOB |
|
| Back to top |
|
 |  |
External

Since: Aug 29, 2008 Posts: 32
|
(Msg. 2) Posted: Wed Oct 01, 2008 10:10 pm
Post subject: Re: Walking a CLOB [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
"jefftyzzer" <jefftyzzer DeleteThis @sbcglobal.net> wrote in message
news:4089c0da-f790-4944-b732-c224f2703e6d@e17g2000hsg.googlegroups.com...
> Friends:
>
> I'm in the unenviable position of having to retrieve rows based on a
> deep-dive into a CLOB, searching for a particular constant.
>
> I've tried different options of predicates and their placement, and
> listed below--in the order of best cost to worst--are the ones I've
> tried:
>
> 1. LIKE predicate, e.g., CLOB_FIELD LIKE '%characterstring%' in the
> WHERE clause
> 2. LOCATE predicate, e.g., LOCATE('characterstring', CLOB_FIELD) > 0
> in the WHERE clause
> 3. POSSTR predicate, e.g., POSSTR (CLOB_FIELD, 'characterstring') > 0
> in the WHERE clause
> 4. Same as 1, but in a CASE statement in the SELECT clause, e.g. CASE
> WHEN CLOB_FIELD LIKE...
> 5. Same as 2, but in a CASE statement in the SELECT clause, e.g. CASE
> WHEN 0 < LOCATE...
> 6. Same as 3, but in a CASE statement in the SELECT clause, e.g., CASE
> WHEN 0 < POSSTR...
>
> Let me add that the table with the CLOB is also being joined-to, and,
> as one might expect, it doesn't matter if I move predicates 1-3 from
> the WHERE to the ON clause.
>
> Finally, note that my platform is DB2 8.2 LUW on AIX 5.2, so I don't
> have the relevant XML functions in 9.x available to me.
>
> My question is this: focusing just on queries 1 and 4, despite what
> the EXPLAIN tells me, the query with the LIKE in a CASE statement in
> the SELECT clause is executing much faster than the one with the LIKE
> in the WHERE. In other words, 4 costs more than 1, but performs
> considerably better.
>
> Why might this be? Is there an optimizer-level difference in the way
> predicates are handled in the WHERE clause versus the SELECT clause?
> Another wrinkle is that CLOBs are "handled" outside of the buffer
> cache, so looking under the hood only shows so much. Feel free also to
> let me know if there's another v8-compatible CLOB-crawling technique
> I'm overlooking.
>
> Thanks,
>
> --Jeff
Anytime you use a function on a predicate, chances are very poor that DB2
can use b-tree index access on that predicate.
DB2 V8.2 has XML Extender, which does provide some additional functions that
can be used to search XML.
If you CLOB is less than 32K (or the max varchar length) then you could try
casting the CLOB to a varchar and then applying the functions against the
varchar to see if that gives you more flexibility (probably not any better
performance. If your CLOB is less than the max varchar, then you should make
it varchar to begin with so you will get much fast access through the
bufferpools (LOB's bypass the bufferpools and require synchronous I/O for
read and write). >> Stay informed about: Walking a CLOB |
|
| Back to top |
|
 |  |
External

Since: Jan 14, 2008 Posts: 65
|
(Msg. 3) Posted: Thu Oct 02, 2008 10:07 am
Post subject: Re: Walking a CLOB [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Oct 1, 7:10 pm, "Mark A" <some....RemoveThis@someone.com> wrote:
> "jefftyzzer" <jefftyz....RemoveThis@sbcglobal.net> wrote in message
>
> news:4089c0da-f790-4944-b732-c224f2703e6d@e17g2000hsg.googlegroups.com...
>
>
>
> > Friends:
>
> > I'm in the unenviable position of having to retrieve rows based on a
> > deep-dive into a CLOB, searching for a particular constant.
>
> > I've tried different options of predicates and their placement, and
> > listed below--in the order of best cost to worst--are the ones I've
> > tried:
>
> > 1. LIKE predicate, e.g., CLOB_FIELD LIKE '%characterstring%' in the
> > WHERE clause
> > 2. LOCATE predicate, e.g., LOCATE('characterstring', CLOB_FIELD) > 0
> > in the WHERE clause
> > 3. POSSTR predicate, e.g., POSSTR (CLOB_FIELD, 'characterstring') > 0
> > in the WHERE clause
> > 4. Same as 1, but in a CASE statement in the SELECT clause, e.g. CASE
> > WHEN CLOB_FIELD LIKE...
> > 5. Same as 2, but in a CASE statement in the SELECT clause, e.g. CASE
> > WHEN 0 < LOCATE...
> > 6. Same as 3, but in a CASE statement in the SELECT clause, e.g., CASE
> > WHEN 0 < POSSTR...
>
> > Let me add that the table with the CLOB is also being joined-to, and,
> > as one might expect, it doesn't matter if I move predicates 1-3 from
> > the WHERE to the ON clause.
>
> > Finally, note that my platform is DB2 8.2 LUW on AIX 5.2, so I don't
> > have the relevant XML functions in 9.x available to me.
>
> > My question is this: focusing just on queries 1 and 4, despite what
> > the EXPLAIN tells me, the query with the LIKE in a CASE statement in
> > the SELECT clause is executing much faster than the one with the LIKE
> > in the WHERE. In other words, 4 costs more than 1, but performs
> > considerably better.
>
> > Why might this be? Is there an optimizer-level difference in the way
> > predicates are handled in the WHERE clause versus the SELECT clause?
> > Another wrinkle is that CLOBs are "handled" outside of the buffer
> > cache, so looking under the hood only shows so much. Feel free also to
> > let me know if there's another v8-compatible CLOB-crawling technique
> > I'm overlooking.
>
> > Thanks,
>
> > --Jeff
>
> Anytime you use a function on a predicate, chances are very poor that DB2
> can use b-tree index access on that predicate.
>
> DB2 V8.2 has XML Extender, which does provide some additional functions that
> can be used to search XML.
>
> If you CLOB is less than 32K (or the max varchar length) then you could try
> casting the CLOB to a varchar and then applying the functions against the
> varchar to see if that gives you more flexibility (probably not any better
> performance. If your CLOB is less than the max varchar, then you should make
> it varchar to begin with so you will get much fast access through the
> bufferpools (LOB's bypass the bufferpools and require synchronous I/O for
> read and write).
Hi, Mark.
I hear you about the predicate vis a vis a b-tree index, but, as DB2
doesn't allow such columns to be indexed, the CLOB field isn't indexed
(nor would I create an index on such a large column even if it were
possible), so that's not the issue in this case.
Also, the CLOB is 1M, and like you said, if the size were in the range
of a VARCHAR, I would have created as such to begin with.
As to the XML extender, I appreciate the suggestion, and regret that
it's not an option in my environment (I know, I know).
The gist of my question, though, was really about the evaluation of
CLOBs in the SELECT vs the WHERE. Let me know if you've got any
thoughts on this.
Thanks for taking the time to read and respond to my post.
Regards,
--Jeff >> Stay informed about: Walking a CLOB |
|
| Back to top |
|
 |  |
| Related Topics: | CLOB data is getting truncated on SELECT - When I am SELECT'ing a CLOB column from command prompt, the output is getting truncated after a certail limit (8 K ??) How do I get the full data out of a CLOB column? Are there any string manipuration functions for CLOB fields to read it in multiple..
PL/1 DB2 V8 Table Declaration for a CLOB - Hi, I am writing a PL/1 program which will be reading a DB2 Table which has a column defined as a CLOB. Therefore, I should use DCLGEN to obtain accurate SQL DECLARE TABLE statements. However I do not have authority, at this company, to use DCLGEN and a...
DB2 UDB LUW 8.2:clp 32 bit connect to 64 bit engine - Environment: DB2 UDB LUW (AIX) 8.2 Database instance: test migration to 64 bit Clients: 32 bit, embedded sql, db2 clp When PATH/LIBPATH point to the 32 lib environment (/usr/opt/db2_08_01/bin and (/usr/opt/db2_08_01/lib) db2..
How to reterive the last 5 records in a table? - Hi I have a table which contains number of rows. I want to fetch the last 5 records from the table. I know for the first 'n' records we can use FETCH FIRST n ROWS ONLY command. But i want to fetch last 5 records. Can any one help in this... ..
"FIND" command is narrowed - In the ISPF editor I am using, for a particullar PO Dataset I am getting the result of FIND statement narrowed down to the colums 48-56. i.e. if I give "FIND 'TO' ALL", the result I am getting as "CHARS 'TO' - found 239 times within colum... |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|