473,796 Members | 2,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CAST function and performance

I hope I am posting to the correct group for assistance. Please advise me
if there is another group I should go to.

I am new to this, so I apologize if I don't explain this very well. I do
need some help. Thanks in advance.

I am trying to bring data in to a Visual Foxpro application from an AS/400.
I have the Client Access ODBC driver loaded on a PC running WinXP. The SQL
query I have made works fine, except it is really slow to pull a record. If
I eliminate the CAST function I can pull a record quickly with another
utility program. Also I have brought this data into Microsoft Access and
can pull a record quickly. I need the CAST function because the data is
stored as text and the Foxpro program requires it as a number. I realize it
may be easier to change the data stored as text to a number on the AS/400
side. I am told this cannot be done right now due to other programs
designed around it. I am posting my script below.

I am sorry if I have not used the correct terms above, I am learning on my
own.

select F4006.OAMLNM, F4006.OAADD1, F4006.OAADD2, F4006.OAADD3, F4006.OACTY1,
F4006.OAADDS, F4006.OAADDZ, F4006.OADOCO, F4006.OAANTY, F4201LA.SHASN,
F4006.OADCTO
from F4006, F4201LA
where F4006.OADOCO = CAST (SUBSTRING('<<P rompt>>',1,6)AS INTEGER) and
F4006.OAANTY = '2' and F4201LA.SHDOCO = F4006.OADOCO and OADCTO = SUBSTRING
('<<Prompt>>',1 0,2)

The '<<Prompt>>' is where my program prompts me for the input. It then
finds a record based on this prompt.
ie; I may enter '555123 SO' and need to look up a record with invoice #
555123 and type 'SO'. It needs to be entered just like this '555123 SO'
as it is scanned in with a barcode. There is too much programming involved
right now to change the input. Also there is one column of data that is
pulled from another table (F4201LA) and I have this written to pull it
correctly.
Nov 12 '05 #1
7 24847
I'm not a DB2 for iSeries expert, but it could be that the version you
are using does not "fold" (compute) (presuming the input is a constant
rather a hostvariable or parameter marker) during teh compileation.
This may possibly throw the optimizer of giving you a suboptimal plan.
Coudl you do that computation in your ptogram and pass in the correct
values/hostvariable to begin with?

DB2 for LUW (the area of my expertiese) doesn't experience those issues
in general, so I'm a bit poking in the dark here....

Cheers
Serge
Nov 12 '05 #2
Thank you for the suggestion. I may try that. Also I have heard that I may
be doing a JOIN and have not configured it correctly. Can you tell if there
is a JOIN going on here? How would I correct that?
"Serge Rielau" <sr*****@ca.ibm .com> wrote in message
news:2t******** *****@uni-berlin.de...
I'm not a DB2 for iSeries expert, but it could be that the version you
are using does not "fold" (compute) (presuming the input is a constant
rather a hostvariable or parameter marker) during teh compileation.
This may possibly throw the optimizer of giving you a suboptimal plan.
Coudl you do that computation in your ptogram and pass in the correct
values/hostvariable to begin with?

DB2 for LUW (the area of my expertiese) doesn't experience those issues
in general, so I'm a bit poking in the dark here....

Cheers
Serge

Nov 12 '05 #3
Yes, there is a join here.
The query is semantically equivalent to:

select F4006.OAMLNM, F4006.OAADD1, F4006.OAADD2, F4006.OAADD3, F4006.OACTY1,
F4006.OAADDS, F4006.OAADDZ, F4006.OADOCO, F4006.OAANTY, F4201LA.SHASN,
F4006.OADCTO
from F4006 INNER JOIN F4201LA ON F4201LA.SHDOCO = F4006.OADOCO
where F4006.OADOCO = CAST (SUBSTRING('<<P rompt>>',1,6)AS INTEGER) and
F4006.OAANTY = '2' and OADCTO = SUBSTRING
('<<Prompt>>',1 0,2)

I know that in DB2 for LUW the way you write this query would not
matter. The path chosen by the optimizer would be the same.
Possibly the system does not recognize teh transitivity that also pins
F4201LA.SHDOCO = CAST (SUBSTRING('<<P rompt>>',1,6)AS INTEGER)
Maybe adding this predicate would help?

Cheers
Serge
Nov 12 '05 #4
There is a general rule that says that the fastest processing is the one you
don't do. Perhaps DB2 will fold your expression, perhaps not. There is no
reason why you can't evaluate it in your application up front.
<quote>
CAST (SUBSTRING('<<P rompt>>',1,6)AS INTEGER)
The '<<Prompt>>' is where my program prompts me for the input.
</quote>
It will be faster for you to pre-process the prompt in your application to
extract the invoice number from the user's input. This is even more so,
since you can verify the input (did the user correctly enter properly
formatted data) and thus avoid queries that fail when the first 6 characters
of the input are not a legal integer.

"VPaul" <vp*****@NOSPAM PLS.earthlink.n et> wrote in message
news:WO******** *********@newsr ead1.news.pas.e arthlink.net...
I hope I am posting to the correct group for assistance. Please advise me
if there is another group I should go to.

I am new to this, so I apologize if I don't explain this very well. I do
need some help. Thanks in advance.

I am trying to bring data in to a Visual Foxpro application from an
AS/400.
I have the Client Access ODBC driver loaded on a PC running WinXP. The
SQL
query I have made works fine, except it is really slow to pull a record.
If
I eliminate the CAST function I can pull a record quickly with another
utility program. Also I have brought this data into Microsoft Access and
can pull a record quickly. I need the CAST function because the data is
stored as text and the Foxpro program requires it as a number. I realize
it
may be easier to change the data stored as text to a number on the AS/400
side. I am told this cannot be done right now due to other programs
designed around it. I am posting my script below.

I am sorry if I have not used the correct terms above, I am learning on
my
own.

select F4006.OAMLNM, F4006.OAADD1, F4006.OAADD2, F4006.OAADD3,
F4006.OACTY1,
F4006.OAADDS, F4006.OAADDZ, F4006.OADOCO, F4006.OAANTY, F4201LA.SHASN,
F4006.OADCTO
from F4006, F4201LA
where F4006.OADOCO = CAST (SUBSTRING('<<P rompt>>',1,6)AS INTEGER) and
F4006.OAANTY = '2' and F4201LA.SHDOCO = F4006.OADOCO and OADCTO =
SUBSTRING
('<<Prompt>>',1 0,2)

The '<<Prompt>>' is where my program prompts me for the input. It then
finds a record based on this prompt.
ie; I may enter '555123 SO' and need to look up a record with invoice
#
555123 and type 'SO'. It needs to be entered just like this '555123 SO'
as it is scanned in with a barcode. There is too much programming
involved
right now to change the input. Also there is one column of data that is
pulled from another table (F4201LA) and I have this written to pull it
correctly.

Nov 12 '05 #5
Thanks for your reply. I have been trying to find out in my application
where the <prompt> is stored so I can evaluate it from there. I have been
able to come up with a somewhat different solution that works at home on my
PC with the data in a MS Access table. However when I try it at my
customers site with their AS/400 I get errors. I am assuming that the
functions and expressions may not be supported by the AS/400. Can you look
at this and tell me how to modify this script that works in MS Access so it
will work at my customers site? Thanks
select F4006.OAMLNM, F4006.OAADD1, F4006.OAADD2, F4006.OAADD3, F4006.OACTY1,
F4006.OAADDS, F4006.OAADDZ, F4006.OADOCO, OAANTY, F4201.SHASN, OADCTO,
F4006.OADCTO

from f4006, F4201

where F4006.OADOCO &' '& F4006.OADCTO = '540030 SO' and F4006.OAANTY = '2'
and F4201.SHDOCO = F4006.OADOCO

Last time I tried this at my customers site I got an error about the token &
being invalid.

I have been looking into the CONCAT expression and have read that a binary
string cannot be concatenated with a character string. So I don't know if
this will totally work either.
"Mark Yudkin" <my************ ***********@boi ng.org> wrote in message
news:ck******** **@ngspool-d02.news.aol.co m...
There is a general rule that says that the fastest processing is the one you don't do. Perhaps DB2 will fold your expression, perhaps not. There is no
reason why you can't evaluate it in your application up front.
<quote>
CAST (SUBSTRING('<<P rompt>>',1,6)AS INTEGER)
The '<<Prompt>>' is where my program prompts me for the input.
</quote>
It will be faster for you to pre-process the prompt in your application to
extract the invoice number from the user's input. This is even more so,
since you can verify the input (did the user correctly enter properly
formatted data) and thus avoid queries that fail when the first 6 characters of the input are not a legal integer.

"VPaul" <vp*****@NOSPAM PLS.earthlink.n et> wrote in message
news:WO******** *********@newsr ead1.news.pas.e arthlink.net...
I hope I am posting to the correct group for assistance. Please advise me if there is another group I should go to.

I am new to this, so I apologize if I don't explain this very well. I do need some help. Thanks in advance.

I am trying to bring data in to a Visual Foxpro application from an
AS/400.
I have the Client Access ODBC driver loaded on a PC running WinXP. The
SQL
query I have made works fine, except it is really slow to pull a record.
If
I eliminate the CAST function I can pull a record quickly with another
utility program. Also I have brought this data into Microsoft Access and can pull a record quickly. I need the CAST function because the data is
stored as text and the Foxpro program requires it as a number. I realize it
may be easier to change the data stored as text to a number on the AS/400 side. I am told this cannot be done right now due to other programs
designed around it. I am posting my script below.

I am sorry if I have not used the correct terms above, I am learning on
my
own.

select F4006.OAMLNM, F4006.OAADD1, F4006.OAADD2, F4006.OAADD3,
F4006.OACTY1,
F4006.OAADDS, F4006.OAADDZ, F4006.OADOCO, F4006.OAANTY, F4201LA.SHASN,
F4006.OADCTO
from F4006, F4201LA
where F4006.OADOCO = CAST (SUBSTRING('<<P rompt>>',1,6)AS INTEGER) and
F4006.OAANTY = '2' and F4201LA.SHDOCO = F4006.OADOCO and OADCTO =
SUBSTRING
('<<Prompt>>',1 0,2)

The '<<Prompt>>' is where my program prompts me for the input. It then
finds a record based on this prompt.
ie; I may enter '555123 SO' and need to look up a record with invoice #
555123 and type 'SO'. It needs to be entered just like this '555123 SO' as it is scanned in with a barcode. There is too much programming
involved
right now to change the input. Also there is one column of data that is
pulled from another table (F4201LA) and I have this written to pull it
correctly.


Nov 12 '05 #6
Thanks for your reply to me.

In RESPONSE to:....

"Possibly the system does not recognize teh transitivity that also pins
F4201LA.SHDOCO = CAST (SUBSTRING('<<P rompt>>',1,6)AS INTEGER)
Maybe adding this predicate would help?"

I tried this and eventually got a message about being out of resources. It
took an exceptionally long time before the error came up

"Serge Rielau" <sr*****@ca.ibm .com> wrote in message
news:2t******** *****@uni-berlin.de...
Yes, there is a join here.
The query is semantically equivalent to:

select F4006.OAMLNM, F4006.OAADD1, F4006.OAADD2, F4006.OAADD3, F4006.OACTY1, F4006.OAADDS, F4006.OAADDZ, F4006.OADOCO, F4006.OAANTY, F4201LA.SHASN,
F4006.OADCTO
from F4006 INNER JOIN F4201LA ON F4201LA.SHDOCO = F4006.OADOCO
where F4006.OADOCO = CAST (SUBSTRING('<<P rompt>>',1,6)AS INTEGER) and
F4006.OAANTY = '2' and OADCTO = SUBSTRING
('<<Prompt>>',1 0,2)

I know that in DB2 for LUW the way you write this query would not
matter. The path chosen by the optimizer would be the same.
Possibly the system does not recognize teh transitivity that also pins
F4201LA.SHDOCO = CAST (SUBSTRING('<<P rompt>>',1,6)AS INTEGER)
Maybe adding this predicate would help?

Cheers
Serge

Nov 12 '05 #7
> Last time I tried this at my customers site I got an error about the token
&
being invalid. As you should have expected, given that it _is_ invalid.

I can't answer the rest of your question (CONCAT) as you haven't given your
schema.

DB2 is not MS Access. DB2 is a database, Access's "database" is a shared
file with an Access-specific dialect of a functionally limited SQL subset;
any resemblance being coincidental. MS Access can be used to front-end SQL
Server, DB2 and the like, but "Access tables" (aka Jet engine) are for
standalone home users with no ACID requirements.

I suggest you consult the DB2 documentation.

"VPaul" <vp*****@NOSPAM PLS.earthlink.n et> wrote in message
news:VO******** ********@newsre ad1.news.pas.ea rthlink.net... Thanks for your reply. I have been trying to find out in my application
where the <prompt> is stored so I can evaluate it from there. I have been
able to come up with a somewhat different solution that works at home on
my
PC with the data in a MS Access table. However when I try it at my
customers site with their AS/400 I get errors. I am assuming that the
functions and expressions may not be supported by the AS/400. Can you
look
at this and tell me how to modify this script that works in MS Access so
it
will work at my customers site? Thanks
select F4006.OAMLNM, F4006.OAADD1, F4006.OAADD2, F4006.OAADD3,
F4006.OACTY1,
F4006.OAADDS, F4006.OAADDZ, F4006.OADOCO, OAANTY, F4201.SHASN, OADCTO,
F4006.OADCTO

from f4006, F4201

where F4006.OADOCO &' '& F4006.OADCTO = '540030 SO' and F4006.OAANTY = '2'
and F4201.SHDOCO = F4006.OADOCO

Last time I tried this at my customers site I got an error about the token
&
being invalid.

I have been looking into the CONCAT expression and have read that a binary
string cannot be concatenated with a character string. So I don't know if
this will totally work either.
"Mark Yudkin" <my************ ***********@boi ng.org> wrote in message
news:ck******** **@ngspool-d02.news.aol.co m...
There is a general rule that says that the fastest processing is the one

you
don't do. Perhaps DB2 will fold your expression, perhaps not. There is no
reason why you can't evaluate it in your application up front.
<quote>
CAST (SUBSTRING('<<P rompt>>',1,6)AS INTEGER)
The '<<Prompt>>' is where my program prompts me for the input.
</quote>
It will be faster for you to pre-process the prompt in your application
to
extract the invoice number from the user's input. This is even more so,
since you can verify the input (did the user correctly enter properly
formatted data) and thus avoid queries that fail when the first 6

characters
of the input are not a legal integer.

"VPaul" <vp*****@NOSPAM PLS.earthlink.n et> wrote in message
news:WO******** *********@newsr ead1.news.pas.e arthlink.net...
>I hope I am posting to the correct group for assistance. Please advise me > if there is another group I should go to.
>
> I am new to this, so I apologize if I don't explain this very well. I do > need some help. Thanks in advance.
>
> I am trying to bring data in to a Visual Foxpro application from an
> AS/400.
> I have the Client Access ODBC driver loaded on a PC running WinXP. The
> SQL
> query I have made works fine, except it is really slow to pull a
> record.
> If
> I eliminate the CAST function I can pull a record quickly with another
> utility program. Also I have brought this data into Microsoft Access and > can pull a record quickly. I need the CAST function because the data
> is
> stored as text and the Foxpro program requires it as a number. I realize > it
> may be easier to change the data stored as text to a number on the AS/400 > side. I am told this cannot be done right now due to other programs
> designed around it. I am posting my script below.
>
> I am sorry if I have not used the correct terms above, I am learning
> on
> my
> own.
>
> select F4006.OAMLNM, F4006.OAADD1, F4006.OAADD2, F4006.OAADD3,
> F4006.OACTY1,
> F4006.OAADDS, F4006.OAADDZ, F4006.OADOCO, F4006.OAANTY, F4201LA.SHASN,
> F4006.OADCTO
> from F4006, F4201LA
> where F4006.OADOCO = CAST (SUBSTRING('<<P rompt>>',1,6)AS INTEGER) and
> F4006.OAANTY = '2' and F4201LA.SHDOCO = F4006.OADOCO and OADCTO =
> SUBSTRING
> ('<<Prompt>>',1 0,2)
>
> The '<<Prompt>>' is where my program prompts me for the input. It then
> finds a record based on this prompt.
> ie; I may enter '555123 SO' and need to look up a record with invoice > #
> 555123 and type 'SO'. It needs to be entered just like this '555123 SO' > as it is scanned in with a barcode. There is too much programming
> involved
> right now to change the input. Also there is one column of data that
> is
> pulled from another table (F4201LA) and I have this written to pull it
> correctly.
>
>



Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
3347
by: Jamie Burns | last post by:
Hello, I am writing a client / server application. There is 1 server, and many clients. The server processes requests from each client, and typically creates and manipulates C++ objects on their behalf. Now, when a client requests for an object to be created, I pass back a pointer to the object (from server memory address scope) as a "long integer". To the client, this is just an ID for the object they wish to access. From then on,...
1
2616
by: Ted | last post by:
I need some tips to boost the performance on the following query. The problem is that it times out once in a while, and then again runs normally in most cases. The clue is to compare a textual value stored as an image data type, but I don't know if the cast operation could be done in another way. Any tips? SELECT DISTINCT pk_product FROM tbl_product P JOIN tbl_product_content PC ON P.pk_product = PC.fk_product JOIN tbl_content C ON...
0
3595
by: Aaron W. West | last post by:
Fun with CAST! (Optimized SQLServerCentral script posts) I found some interesting "tricks" to convert binary to hexadecimal and back, which allow doing 4 or 8 at a time. Test code first: -- These two have the same output, other than the width: select dbo.ufn_vbintohexstr(0x123456789abcdef1234) select 0x123456789abcdef1234
5
2586
by: MC | last post by:
Hi If I have a pointer to a some structure say for example payroll_ptr where struct payroll { ... } has some members and if i use a function argument as int function_process ( (payroll_ptr) 0 , ..) does the first argument become a NULL pointer ?
17
2677
by: Hazz | last post by:
In this sample code of ownerdraw drawmode, why does the '(ComboBox) sender' line of code need to be there in this event handler? Isn't cboFont passed via the managed heap, not the stack, into this cboFont_DrawItem event handler? Why does it need to be cast? -hazz ,................. cboFont.Items.AddRange(FontFamily.Families); } private void cboFont_DrawItem(object sender,
16
11288
by: Martin Jørgensen | last post by:
Hi, Short question: Any particular reason for why I'm getting a warning here: (cast from function call of type int to non-matching type double) xdouble = (double)rand()/(double)RAND_MAX;
7
5292
by: llothar | last post by:
When i use -W4 on visual c 7.0 i get warning C4054 translator1.c(1703) : warning C4054: 'type cast' : from function pointer 'void * (__cdecl *)(se_agent *)' to data pointer 'void *' translator1.c(1703) : warning C4152: nonstandard extension, function/ data pointer conversion in expression whenever i cast a function pointer to a void* or back. Is there any reason for this warning ? Looks like good C code for me.
3
10669
by: Arnie | last post by:
Folks, We ran into a pretty significant performance penalty when casting floats. We've identified a code workaround that we wanted to pass along but also was wondering if others had experience with this and if there is a better solution. -jeff
4
2539
by: Pavel Minaev | last post by:
There was an earlier discussion regarding which one is faster - a throwing cast - "(Foo)obj", or a non-throwing one - "obj as Foo", when both are available for a given type and value. The consensus was that, since a check has to be made by the compiler in either case, the speed should be equivalent in case object is indeed of a requested type. Sounds perfectly reasonable, but I've spotted the following in the .NET source code (from MS...
0
10449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10168
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9047
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.