473,396 Members | 2,033 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,396 software developers and data experts.

Improving performance with a Function instead of a View

Hi all,
I am using some views now to put together a particular format for my
Java client factory to produce Java Beans from the database.

Because we support internationalisation we are representing values as an
id then storing their multiple languages in unicode to support the same
repesentation at the database.

This format is:

base_table, id bigint, is_disabled boolean default false.

resource_table, foreign_key_to_base_table, locale_foreign_key,
display_name, is_translated

As such, my views are quite slow because there are a number of Right
Joins occuring so that I can present a single "locale" field in the view
that all the localised information will attach to correctly.

That way I can > select * FROM v_object where locale = 'en_GB' and
object_id = 120031;

So if there are three localised joins they are bound to the single
locale.

E.G

create view v_object as
select loc.id as locale,
obj.id as object_id,
obj.user_data as user_data,

type.id as object_type,
type_res.disp_name as object_type_display_name

size.id as object_size,
size_res.disp_name as object_size_disp_name

from locale as loc,
object as obj
left join object_type as type on type.id = obj.object_type
left join object_type_res as type_res on
type_res.object_type = obj.object_type
left join object_size as size on size.id = obj.object_size
left join object_size_res as size_res on
size_res.object_size = obj.object_size
where ( type_res.locale = loc.id OR type_res.locale IS NULL ) AND
( size_res.locale = loc.id OR size_res.locale IS NULL );

In this example the left joins are required to ensure the columns are
returned even if null as not all fields are required.

Anyway, there is a performance problem, and we have a temporary
solution.

I was wondering if it is possible to create a function that will return
a set of data with the correct view names and have this function perform
additional and fast checks server side?

Regards
--
Hadley Willan » Director » ha***********@deeperdesign.com » +64(21) 28
41 463
Deeper Design Limited » +64(7) 377 3328 » www.deeperdesign.com

Nov 22 '05 #1
3 1892
Hadley Willan wrote:
Hi all,
I am using some views now to put together a particular format for
my Java client factory to produce Java Beans from the database.

Because we support internationalisation we are representing values as
an id then storing their multiple languages in unicode to support the
same repesentation at the database.

This format is:

base_table, id bigint, is_disabled boolean default false.

resource_table, foreign_key_to_base_table, locale_foreign_key,
display_name, is_translated

As such, my views are quite slow because there are a number of Right
Joins occuring so that I can present a single "locale" field in the
view that all the localised information will attach to correctly.

That way I can > select * FROM v_object where locale = 'en_GB' and
object_id = 120031;

Without taking the view definition into account, the above query could
not use an index on object_id because it is of type 'bigint', but the
integer constant is parsed as 'integer'. It must either be rewritten as:

object_id = 120031::bigint

or

object_id = '120031'

or set the sequence for this identifier to start fetching values > 4.2
billion (32-bit numbers). Of course, the view definition may have other
optimization possibilities as well...

Mike Mascari

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 22 '05 #2
Thanks, but I don't believe this to be a problem because my JDBC layer
when I construct the query is using setObject( parameter, getId,
Types.BIGINT )

so by the time it arrives at the database that cast should have already
occured?

I could be wrong but running the Explain Analyse shows indexes being
used, but the right join for the locale stuff is the killer.

Thanks

On Thu, 2004-02-05 at 13:31, Mike Mascari wrote:
Hadley Willan wrote:
Hi all,
I am using some views now to put together a particular format for
my Java client factory to produce Java Beans from the database.

Because we support internationalisation we are representing values as
an id then storing their multiple languages in unicode to support the
same repesentation at the database.

This format is:

base_table, id bigint, is_disabled boolean default false.

resource_table, foreign_key_to_base_table, locale_foreign_key,
display_name, is_translated

As such, my views are quite slow because there are a number of Right
Joins occuring so that I can present a single "locale" field in the
view that all the localised information will attach to correctly.

That way I can > select * FROM v_object where locale = 'en_GB' and
object_id = 120031;

Without taking the view definition into account, the above query could
not use an index on object_id because it is of type 'bigint', but the
integer constant is parsed as 'integer'. It must either be rewritten as:

object_id = 120031::bigint

or

object_id = '120031'

or set the sequence for this identifier to start fetching values > 4.2
billion (32-bit numbers). Of course, the view definition may have other
optimization possibilities as well...

Mike Mascari


--
Hadley Willan » Director » ha***********@deeperdesign.com » +64(21) 28
41 463
Deeper Design Limited » +64(7) 377 3328 » www.deeperdesign.com

Nov 22 '05 #3


On Thu, 5 Feb 2004, Hadley Willan wrote:
Thanks, but I don't believe this to be a problem because my JDBC layer
when I construct the query is using setObject( parameter, getId,
Types.BIGINT )

so by the time it arrives at the database that cast should have already
occured?


The JDBC driver will not do any casting for you. The cross type indexing
problem is is a backend issue and has been addressed in the cvs version,
but this has long been a problem for JDBC users.

Kris Jurka
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 22 '05 #4

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

Similar topics

3
by: Andy Tran | last post by:
I built a system using mysql innodb to archive SMS messages but the innodb databases are not keeping up with the number of SMS messages coming in. I'm looking for performance of 200 msgs/sec where...
6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
5
by: Steve_CA | last post by:
Hello all, I've been recruited to assist in diagnosing and fixing a performance problem on an application we have running on SQL Server 7. The application itself is third party software, so we...
0
by: Alex Vinokur | last post by:
=================================== ------------- Sorting ------------- Comparative performance measurement =================================== Testsuite : Comparing Function Objects to...
6
by: Matik | last post by:
Hello all, I've following problem. Please forgive me not posting script, but I think it won't help anyway. I've a table, which is quite big (over 5 milions records). Now, this table contains...
9
by: Java script Dude | last post by:
In many languages, it is necessary to string together multiple strings into one string for use over multiple lines of code. Which one is the most efficient from the interpreters perspective: ...
29
by: Olaf Baeyens | last post by:
Because of historical reasons, I have both C# and C++ managed/unmanaged code mixed together in my class library. But I prefer to port code to C# since it compiles faster and the syntax is much...
1
by: Robin | last post by:
For an asp.net project that is deployed to a load balanced web servers, are there any performance changes that can be made in .Net runtime or IIS 6? Also are there any additional tips for...
5
by: Rahul B | last post by:
Hi, We have been migrating to DB2 and it has been the trend that the application has become somewhat slow. It could be because of the application problems or it could be because i am not very...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
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,...

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.