473,854 Members | 1,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help needed with slow query

I have a large table (~200 columns, ~10 million rows) and I am trying
to query by two float rows, say f1 and f2:
SELECT... FROM large_table WHERE f1 BETWEEN 10.82 AND 113.998 AND f2
BETWEEN -124.99 AND 23.5;
The query is extremely slow; it takes hours.
Question 1: Is it ok to have to indexes one by f1 and another by f1 or
should I have one index by (f1, f2)?
Question 2: How can I speed it up?
Any help is appreciated.
Thanks.
Gabe Chime

Oct 19 '05 #1
2 1596
>I have a large table (~200 columns, ~10 million rows) and I am trying
to query by two float rows, say f1 and f2:
SELECT... FROM large_table WHERE f1 BETWEEN 10.82 AND 113.998 AND f2
BETWEEN -124.99 AND 23.5;
The query is extremely slow; it takes hours.
What indexes do you have now? None?
Question 1: Is it ok to have to indexes one by f1 and another by f1 or
should I have one index by (f1, f2)?
Having two single indexes on the same variable is pointless.
If you have two separate indexes, one on f1 and one on f2, MySQL
might be able to use the one with the fewest records in the range.

An index on (f1, f2) is no better than (and probably worse than) an
index on f1 alone. It would be usable for an exact match on f1 and
a range on f2.

What other queries use this table?
Question 2: How can I speed it up?


Delete most of the records?

Gordon L. Burditt

Oct 20 '05 #2
g_*****@yahoo.c om wrote:
Question 1: Is it ok to have to indexes one by f1 and another by f1 or
should I have one index by (f1, f2)?
It's okay to define indexes either way, but MySQL will use only one
index per table in a given query. So in your case, I'd recommend trying
the compound index and see if it makes a difference to performance.

http://dev.mysql.com/doc/refman/5.0/...l-indexes.html says:

"If a multiple-column index exists on col1 and col2, the appropriate
rows can be fetched directly. If separate single-column indexes exist on
col1 and col2, the optimizer tries to find the most restrictive index by
deciding which index finds fewer rows and using that index to fetch the
rows."

In other words, if you have two separate indexes, one on f1 and one on
f2, the doc appears to say that it can only use one index or the other,
but will try to make the best decision about which of the two to use.

Verify which index the query is using on your given query using EXPLAIN.
Usage of EXPLAIN and interpretation of its output is documented here:
http://dev.mysql.com/doc/refman/5.0/en/explain.html
Question 2: How can I speed it up?


Make sure you do proper index maintenance, with OPTIMIZE TABLE.
Periodic maintenance of indexes is important to make sure they keep
functioning efficiently.

See:
http://dev.mysql.com/doc/refman/5.0/...ize-table.html
http://dev.mysql.com/doc/refman/5.0/...hk-syntax.html

This may be especially important if your table has a lot of activity,
both new insertions and deletions of old records. Based on the values
you mentioned in your search criteria, I'm going to guess that you are
working with scientific measurements of some type, and that you do have
a lot of activity in this table.

Regards,
Bill K.
Oct 20 '05 #3

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

Similar topics

2
6029
by: cricketunes | last post by:
Hi everyone :) I have made a form to get values and insert them to a database. I have 1) A file conn.php that does the initial connections 2) The form file form.php 3) Action file action.php which gets values from form.php to do insert/delete/update.
10
4272
by: tgh003 | last post by:
So lets assume I have a list of tasks in db table (table looks like: ID, task, sort) And I want to reorder the task list without updating all the records in the table. I dont want to run a sql update stmt against every record to update the "sort" field. Any other easy way to do this? there has got to be a simple algo out there.
2
4710
by: berthelot samuel | last post by:
Hi everyone, I am currently trying to write a report based on a View of SQL Server. Basically, I have 3 tables : Hardware, SoftwareInstalled and Software with SoftwareInstalled that keeps track of all the software installed on each piece of hardware by referencing the primary keys of each table. So now, I have a request that retrieve information from those 3 tables giving a list of all the hardware with their details + the software...
0
1520
by: Adam Nemitoff | last post by:
I have two tables populated during the use of an application to log user events and application states. They are named "EventTable" and "StateTable" and the structures follow: EventTable: ID EventTimeStep EventID -- ------------- --------- 1 5 E1 2 22 E2
19
14855
by: Thue Tuxen Sørensen | last post by:
Hi everybody ! I´m maintaining a large intranet (approx 10000 concurrent users) running on one IIS box and one DB box with sqlserver 2000. Currently there is 2,5 GB Ram, 1 1400 mhz cpu and 2 scsi disks installed on the db box. Sqlserver is set to use max 1,4 GB RAM, and the sqlserver does not seem to be using it all.
2
1301
by: Adam Nemitoff | last post by:
I have two tables populated during the use of an application to log user events and application states. They are named "EventTable" and "StateTable" and the structures follow: EventTable: ID EventTimeStep EventID -- ------------- --------- 1 5 E1 2 22 E2
4
1648
by: trint | last post by:
Ok, This script is something I wrote for bringing up a report in reporting services and it is really slow...Is their any problems with it or is their better syntax to speed it up and still provide the same report results?: SELECT t1.MemberId, t1.PeriodID, t8.start_date, t6.amount_type_id, t6.amount_type, SUM(CASE WHEN t2.amountTypeId = 7 THEN t2.amount WHEN t2.amountTypeId = 23 THEN - t2.amount END) AS Purchase,
2
2069
by: nilandanj | last post by:
Hi, I want to solve the slow query problem...can anyone help me for this.. can anyone guide me for this that which GUI tool is helpful for me to solve slow-query???? pls give me answer as early as possible Nilnandan Joshi
3
7079
by: cwoll | last post by:
Hi I need help. I have a ms access 2003 database that I would like to upgrade to ms access 2007. The first time I opened I had to fix a few references it wanted a DAO2535.TLB file witch I gave it, and a utility.mda file witch I think i gave it. The instructions on Microsoft's web sight were not very clear where to put the utility.mda so I am not sure if I have it at the right place. The Database does not ask for it anymore. I have...
0
11024
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
10744
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
10364
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...
1
7909
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
7077
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
5738
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
4550
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
2
4150
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3182
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.