473,809 Members | 2,876 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

max date select stmt problem

Hello Everybody,

I have a problem, with select stmt:

SELECT TOP 15 *
FROM oaVIEW_MainData AS TOP_VIEW,
oaLanguageData_ TAB AS RwQualifierJoin with (nolock)
WHERE (c_dateTime>='2 007.01.10 00:00:00' AND c_dateTime<='20 07.01.10
23:59:59')
AND RwQualifierJoin .text_id = c_cfgRegPoint
AND (((RwQualifierJ oin.local1 LIKE N'Position of any bubu')))
AND TOP_VIEW.c_date Time=(SELECT MAX(SUB_VIEW.c_ dateTime)
FROM oaVIEW_MainData AS SUB_VIEW,oaLang uageData_TAB AS
RwQualifierJoin 1 with (nolock)
WHERE (c_dateTime>='2 007.01.10 00:00:00' AND c_dateTime<='20 07.01.10
23:59:59')
AND RwQualifierJoin 1.text_id = c_cfgRegPoint
AND (((RwQualifierJ oin1.local1 LIKE N'Position of any bubu')))
AND TOP_VIEW.c_dsmI dent=SUB_VIEW.c _dsmIdent)
order by c_dateTime desc
Please consider:
- top doesn't metter, if I will use one or 10000 result is always the
same.
- oaVIEW_MainData , is a view on major big table, holding lot of records
joinden with small table containing configuration data, over left outer
join; both tables are with nolock option,
- quersy supose to return last record from major table/view, in given
time, additionaly, with other where conditions (like in this case with
text),
- on major table, are indexes which one is on id field (not used in
this query at all), which is a pk clustered, and other is on dateEvt
(c_dateTime) which is a desc index with fill level 90%
- table has also other indexes, on three different fields, one of
theses is dsmIdent,

Now, if I'm using max(id) works very fast, and ok for me, but the
problem is, I should not use id, because might be, that the records
will be written in the table with random order, so the only one saying
which is newest, will be dateEvt.

Using dateEvt as max(), dramaticly slows query, so I'm acctualy unable
to get result. What is much more funny, server is totaly busy with this
query, and it's procesor jumps on 100%.

Now, because the query is builded dynamicly, by a user selections,
that's why we decided on such a parser ... problem is, it is not
working :(

Can I change index on dateEvt somehow, to sped this up?
Maybe construct query somehow different, to get this over max() date?

Please help

Matik

Jan 10 '07 #1
1 3719
Matik (ma****@sauron. xo.pl) writes:
- oaVIEW_MainData , is a view on major big table, holding lot of records
joinden with small table containing configuration data, over left outer
join; both tables are with nolock option,
NOLOCK in a view? That's about criminal in my opinion.
- on major table, are indexes which one is on id field (not used in
this query at all), which is a pk clustered, and other is on dateEvt
(c_dateTime) which is a desc index with fill level 90%
- table has also other indexes, on three different fields, one of
theses is dsmIdent,

Now, if I'm using max(id) works very fast, and ok for me, but the
problem is, I should not use id, because might be, that the records
will be written in the table with random order, so the only one saying
which is newest, will be dateEvt.

Using dateEvt as max(), dramaticly slows query, so I'm acctualy unable
to get result. What is much more funny, server is totaly busy with this
query, and it's procesor jumps on 100%.
Well, the easy fix would be to make the index on dateEvt() clustered
rather than the index on id. That may of course have repercussions
elsewhere.

The query looks funny to me, as it repeats the entire outer query in
the subquery. Somehome I feel that that should not be necessary. But
to say for sure I would need to know the view definition and the
definition of the underlying tables, including their key and check
constraints.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jan 11 '07 #2

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

Similar topics

2
2465
by: Andy S. | last post by:
Hi, I'm trying to declare and use temporary tables. I have written the following code in Java. Creating the tablespace (i can see the tablespace created using the Control Center), the temporary table and even inserting the values execute fine (even the executeUpdate while inserting returns a positive number indicating that rows have been inserted). However, when I select * from the temporary table, 0 rows are returned and the while loop...
3
4037
by: anilcool | last post by:
Hi all, This is probably a simple problem for most of you.. Let me know if you have any pointers for me. I am new to DB2. In my stored procedure I want to select records that match a range of values. =========================================================
14
4450
by: peteh | last post by:
Hi All; We have many production jobs that "load from cursor" to a UDB/AIX 8.2 (with dpf) data warehouse from source tables residing Oracle 9i. Since Oracle dates are (roughly) equivalent to DB2 timestamps, we frequently use the date() function to "convert" from the Oracle date datatype to the DB2 date datatype. We have used this technique on over 20 Oracle tables for several months with no problem. One table in particular fails with a...
8
2191
by: TGEAR | last post by:
I have an ItemSTDPriceHistory table as below and this is a child table of itemlookup table with one to many relationship. if exists (select * from dbo.sysobjects where id = object_id(N'.') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table . GO
3
2549
by: satish mullapudi | last post by:
Hi, I am using DB v8.2. when I issuing the following stmt.: "select DATE('25.12.2006')-DATE('24.12.2006')from sysibm.sysdummy1" : 1 "select DATE('25.12.2006')-DATE('24.11.2006')from sysibm.sysdummy1" : 101 "select DATE('25.12.2006')-DATE('25.12.2005')from sysibm.sysdummy1" : 10000 "select DATE('25.12.2006')-DATE('01.12.2005')from sysibm.sysdummy1" : 10024
1
1452
by: jesmi | last post by:
hi i got problem in inserting the date into the database. my requirement is that when i choose a date ie from :2007-01-01 & to :2007-12-01 then all the dates starting from 2007-02-01 upto 2007-12-01 should be inserted. while inserting year,month and day should be incremented.i tried a lot and my code only increments the month. Following is my code: public void save(String eventDt,String toDt) throws Exception{ Connection con =...
2
9757
by: jeanbdenis | last post by:
Hi Folks, I have been struggling with this issues for the last couple of days. I have a java application which does an update to the database every 5 mins. The data written to the database does not change much from one minute to the next. Just the timestamp. While this application runs 24/7, the error occurs once or twice a day (It's an intermittent problem which I have not been able to replicate in my dev environment) below is the...
5
1318
by: pradeep84 | last post by:
Hi .. friends.. in the below program public void actionPerformed(ActionEvent ae) { int flag=0; s1=(from.getText()); s2=(to.getText()); if(ae.getSource()==view) {
2
3740
by: Yew12 | last post by:
We are trying to get the following script to display the full date and time. The field we are calling does have both date and time in. Unfortunatly its only returning the date. So I tried putting the sql "to_date('Adate','dd/mm/yyyy hh24:mi')" to disply the full field. No Luck Any help is much appresiated. Thanks.<HTML> <HEAD><TITLE> Property Results </TITLE> </HEAD> <BODY> <?php $sql="Select * from Appointment where Appointment_id =...
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10633
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...
1
10375
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
10114
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9198
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
7651
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
5548
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...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3011
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.