473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

What is the fastest way...

Hi everyone!

I have two tables, T1 and T2 defined as follows:

create table T1(c1 integer not null,
primary key (c1));
create table T2(c1 integer not null,
c2 varchar(100) not null,
primary key (c1, c2));

populated with example data:

insert into t1 values (1), (2), (3);
insert into t2 values
(1, 'opt 1'),
(1, 'opt 2'),
(1, 'opt 3'),
(2, 'opt 1');

i would like to execute query like this one:
select t1.c1, GetOptions(t1.c1) as options_list from t1 left join t2 on
t1.c1=t2.c1

and get following results:
c1 options_list
------ -------------------------------
1 opt 1, opt 2, opt 3
2 opt 1
3 -

What is the fastest way of implementing GetOptions() function: plaing
with XML, recursive queries, or maybe some external code in C or Java
instead of SQL? Or maybe it's better to implement some processing on the
client side?

Lets assume that table T1 will have about 50k-100k rows, and there will
be 0-20 values of column c2 in table T2 (for each c1 column).

Thanks in advance for any info.

Sincerely,
Dominik Czechowski
Feb 23 '07 #1
5 2428
Dominik Czechowski wrote:
Hi everyone!

I have two tables, T1 and T2 defined as follows:

create table T1(c1 integer not null,
primary key (c1));
create table T2(c1 integer not null,
c2 varchar(100) not null,
primary key (c1, c2));

populated with example data:

insert into t1 values (1), (2), (3);
insert into t2 values
(1, 'opt 1'),
(1, 'opt 2'),
(1, 'opt 3'),
(2, 'opt 1');

i would like to execute query like this one:
select t1.c1, GetOptions(t1.c1) as options_list from t1 left join t2 on
t1.c1=t2.c1

and get following results:
c1 options_list
------ -------------------------------
1 opt 1, opt 2, opt 3
2 opt 1
3 -

What is the fastest way of implementing GetOptions() function: plaing
with XML, recursive queries, or maybe some external code in C or Java
instead of SQL? Or maybe it's better to implement some processing on the
client side?
External C/Java code gets more complicated if you really want to have it
perform the aggregation: http://tinyurl.com/3yfsur
However, you could use a READS SQL DATA function that performs the SELECT on
table T2 internally. Then your query would become:

SELECT t1.c1, GetOptions(t1.c1)
FROM t1
Lets assume that table T1 will have about 50k-100k rows, and there will
be 0-20 values of column c2 in table T2 (for each c1 column).
Is performance really an issue for you? Your tables aren't that big.

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Feb 23 '07 #2
W dniu: 2007-02-23 09:23 Knut Stolze napisal:
Dominik Czechowski wrote:
>>
What is the fastest way of implementing GetOptions() function: plaing
with XML, recursive queries, or maybe some external code in C or Java
instead of SQL? Or maybe it's better to implement some processing on the
client side?

External C/Java code gets more complicated if you really want to have it
perform the aggregation: http://tinyurl.com/3yfsur
However, you could use a READS SQL DATA function that performs the SELECT on
table T2 internally. Then your query would become:

SELECT t1.c1, GetOptions(t1.c1)
FROM t1
>Lets assume that table T1 will have about 50k-100k rows, and there will
be 0-20 values of column c2 in table T2 (for each c1 column).

Is performance really an issue for you? Your tables aren't that big.
Thanks for fast reply and link to your article, I will have to read it
later. As far as size of tables and performance: tables aren't big, but
queries will be running quite frequently, from many clients and that's
why I'm concerned about performance.

Dominik Czechowski
Feb 23 '07 #3
I have an example for string aggregation here:
http://www.iiug.org/waiug/present/Fo...rge_Rielau.ppt

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Feb 23 '07 #4
Why do you wish to destroy First Normal Form (1NF) with a
concatendated list structure? It is the foundation of RDBMS, after
all.

Why are you formatting data in the back end? The basic principle of a
tiered architecture is that display is done in the front end and never
in the back end. This a more basic programming principle than just
SQL and RDBMS.

Yes, there are kludges, but would you prefer to be a good SQL
programmer instead?

Feb 24 '07 #5
Hi,

First of all my intention is not destroying or not 1NF, but achieving
the best possible performance with described data structures (in fact my
structure is a little more complicated). I just wonder if I can write a
UDF fast enough to handle such "reports" with many clients requesting
data even every second. In fact one part of my question was if
processing data on the client side wouldn't be a better option:
>What is the fastest way of implementing GetOptions() function: plaing
with XML, recursive queries, or maybe some external code in C or Java
instead of SQL? Or maybe it's better to implement some processing on
the client side?
When you write an application for more than one environment and have to
write similar code in different programming languages, in my example in
Delphi and php you start to wonder if it is not better to move some code
to database level.

P.S. Some time ago I had a similar problem with hierarchical (tree) data
structures presented in DB2. It worked quite ok with recursive queries
(DB2 v7), however returning raw queries from table and processing it on
the client side was much faster (about 10 times faster). Now, with DB2
v9 I know I could do it using XML, but the question remains - will it
work faster?

P.S.S. I love your books Joe.

Regards
Dominik Czechowski

--CELKO-- pisze:
Why do you wish to destroy First Normal Form (1NF) with a
concatendated list structure? It is the foundation of RDBMS, after
all.

Why are you formatting data in the back end? The basic principle of a
tiered architecture is that display is done in the front end and never
in the back end. This a more basic programming principle than just
SQL and RDBMS.

Yes, there are kludges, but would you prefer to be a good SQL
programmer instead?
Feb 24 '07 #6

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

Similar topics

11
by: Simon | last post by:
Hi, If I have a string, (variable len), and I am looking for the first position of one char in array starting from position 'x' For example, // the 'haystack' $string = "PHP is great,...
6
by: Neal D. Becker | last post by:
I need a fairly small lookup table, and I'm wondering which data python data structure would be fastest. I could use a list, tuple, dictionary, numeric array, or maybe plain python array. The...
137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
7
by: SIgnOff | last post by:
What the fastest way to copy strings from file to a vector in STL?
9
by: Jiho Han | last post by:
Suppose I have an xml fragment like: <mother> <child name="Bob" sex="M"/> <child name="Jane" sex="F"/> ... </mother> If I wanted to replace the <mother> element to <father> element, what is...
3
by: Harry Haller | last post by:
What is the fastest way to search a client-side database? I have about 60-65 kb of data downloaded to the client which is present in 3 dynamically created list boxes. The boxes are filled from 3...
1
by: Harry Haller | last post by:
What is the fastest way to search a client-side database? I have about 60-65 kb of data downloaded to the client which is present in 3 dynamically created list boxes. The boxes are filled from 3...
24
by: ThunderMusic | last post by:
Hi, The subject says it all... I want to use a byte and use it as byte* so I can increment the pointer to iterate through it. What is the fastest way of doing so in C#? Thanks ThunderMusic
22
by: SETT Programming Contest | last post by:
The SETT Programming Contest: The fastest set<Timplementation Write the fastest set<Timplementation using only standard C++/C. Ideally it should have the same interface like std::set. At least...
10
by: timor.super | last post by:
Hi all, Imagine I've an array of int : int anArray = new int; I want to extract all the integer that are superior to 500 I can do :
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.