473,549 Members | 2,592 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with indexes ?

Hi

I have the following database under MySQL 4.1 :

////////////////////////////////////////////////////
# Table structure for table `affiliate_lock out`
#

CREATE TABLE `affiliate_lock out` (
`member_id` bigint(20) NOT NULL default '0',
`affiliate_lock ed_id` bigint(20) NOT NULL default '0',
PRIMARY KEY (`member_id`,`a ffiliate_locked _id`)
) TYPE=MyISAM CHARSET=latin1;

# --------------------------------------------------------

#
# Table structure for table `lead`
#

CREATE TABLE `lead` (
`id` int(11) NOT NULL auto_increment,
`borrower_last_ name` varchar(30) default NULL,
`co_borrower_la st_name` varchar(30) default NULL,
`borrower_ss_nu mber` varchar(20) default NULL,
`prop_address1` varchar(100) default NULL,
`prop_city` varchar(20) default NULL,
`prop_state` char(3) default NULL,
`prop_zip` varchar(10) default NULL,
`home_phone` varchar(15) default NULL,
`office_phone` varchar(15) default NULL,
`prop_type` varchar(30) default NULL,
`prop_is` varchar(30) default NULL,
`prop_value` double default NULL,
`current_value` double default NULL,
`purchase_price ` double default NULL,
`balance` double default NULL,
`first_mortgage _interest_rate` double default NULL,
`first_mortgage _monthly_paymen t` double default NULL,
`down_payment` double default NULL,
`date_acquired` date default NULL,
`behind` tinyint(4) default NULL,
`first_mortgage _fixed_or_ajust ab` varchar(10) default NULL,
`borrower_credi t_rating` varchar(20) default NULL,
`co_borrower_cr edit_rating` varchar(20) default NULL,
`time` varchar(30) default NULL,
`loan_amount` double default NULL,
`loan_type` varchar(50) default NULL,
`email` varchar(60) default NULL,
`information` blob,
`mail_auth` tinyint(4) default '0',
`date_creation` timestamp NOT NULL,
`exclusive` tinyint(4) default NULL,
`prop_address2` varchar(100) default NULL,
`prop_country` varchar(20) default NULL,
`borrower_addre ss1` varchar(100) default NULL,
`borrower_addre ss2` varchar(100) default NULL,
`borrower_zip` varchar(10) default NULL,
`borrower_city` varchar(20) default NULL,
`borrower_state ` char(3) default NULL,
`borrower_count ry` varchar(20) default NULL,
`co_borrower_ss _number` varchar(20) default NULL,
`homeowner` tinyint(4) default '1',
`purchase_date` date default NULL,
`first_mortgage _amount_owed` double default NULL,
`second_mortgag e_amount_owed` double default NULL,
`second_mortgag e_interest_rate ` double default NULL,
`second_mortgag e_fixed_or_ajus ta` varchar(10) default NULL,
`second_mortgag e_monthly_payme nt` double default NULL,
`borrower_first _name` varchar(30) default NULL,
`borrower_emplo yer` varchar(30) default NULL,
`borrower_emplo yer_nb_years` float default NULL,
`borrower_gross _yearly_income` double default NULL,
`co_borrower_fi rst_name` varchar(30) default NULL,
`co_borrower_em ployer` varchar(30) default NULL,
`co_borrower_em ployer_nb_years ` float default NULL,
`co_borrower_gr oss_yearly_inco me` double default NULL,
`nb_units` float default NULL,
`ip_address` varchar(20) default NULL,
`refinance_date ` date default NULL,
`refinance_lien s` double default NULL,
`referer` varchar(150) default NULL,
`bad_lead` tinyint(4) default NULL,
`affiliate_id` bigint(20) default NULL,
`nb_purchases` tinyint(4) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `date_creation` (`date_creation `),
KEY `exclusive` (`exclusive`),
KEY `nb_purchases` (`nb_purchases` )
) TYPE=MyISAM CHARSET=latin1 AUTO_INCREMENT= 8876 ;

# --------------------------------------------------------

#
# Table structure for table `member`
#

CREATE TABLE `member` (
`login` varchar(10) NOT NULL default '',
`website` varchar(15) NOT NULL default '',
`valid` tinyint(4) NOT NULL default '0',
`password` varchar(10) NOT NULL default '',
`balance` double NOT NULL default '0',
`first_name` varchar(20) default NULL,
`last_name` varchar(20) default NULL,
`address1` varchar(100) default NULL,
`city` varchar(20) default NULL,
`state` char(3) default NULL,
`office_phone` varchar(15) default NULL,
`other_phone` varchar(15) default NULL,
`fax` varchar(15) default NULL,
`email` varchar(60) default NULL,
`zip` varchar(10) default NULL,
`loan_types` blob,
`property_types ` varchar(100) default NULL,
`credit_ratings ` varchar(50) default NULL,
`states` varchar(200) default NULL,
`ss_number` varchar(20) default NULL,
`mail_auth` tinyint(4) default '0',
`address2` varchar(100) default NULL,
`country` varchar(20) default NULL,
`company_websit e` varchar(60) default NULL,
`id` bigint(20) NOT NULL default '0',
`date_subscript ion` timestamp NOT NULL,
`company_name` varchar(50) default NULL,
`balance_in_poi nts` double default NULL,
PRIMARY KEY (`id`),
KEY `balance_in_poi nts` (`balance_in_po ints`)
) TYPE=MyISAM CHARSET=latin1;

# --------------------------------------------------------

#
# Table structure for table `member_exclusi on`
#

CREATE TABLE `member_exclusi on` (
`member_id` bigint(20) NOT NULL default '0',
`member_id_to_e xclude` bigint(20) NOT NULL default '0',
PRIMARY KEY (`member_id`,`m ember_id_to_exc lude`)
) TYPE=MyISAM CHARSET=latin1;

# --------------------------------------------------------

#
# Table structure for table `purchase`
#

CREATE TABLE `purchase` (
`lead_id` int(11) NOT NULL default '0',
`date` timestamp NOT NULL,
`automated` tinyint(4) default '0',
`member_id` bigint(20) NOT NULL default '0',
`email_sent` tinyint(4) default '0',
`shared_or_excl usive` varchar(10) default NULL,
PRIMARY KEY (`lead_id`,`mem ber_id`),
KEY `member_id_purc hase_key` (`member_id`),
KEY `lead_id` (`lead_id`)
) TYPE=MyISAM CHARSET=latin1;

////////////////////////////////////////////////////////////
I have to run the following query (maybe it can be optimized, but I
really don't know how ... I sent another post to see if somebody could
optimize it) which is very very slow to run (about 30s).

//////////////////////////////////////////////////////////

SELECT *
FROM lead
WHERE UNIX_TIMESTAMP( now( ) ) - UNIX_TIMESTAMP( date_creation ) <= (
6 * 24 * 3600 ) AND
(exclusive IS NULL OR (exclusive = 0 AND nb_purchases < 3)) AND

id NOT IN (

SELECT lead_id
FROM purchase
WHERE member_id = 21101
) AND affiliate_id NOT
IN (

SELECT affiliate_locke d_id
FROM affiliate_locko ut
WHERE member_id = 21101
) AND id NOT
IN (

SELECT lead_id
FROM purchase
INNER JOIN member_exclusio n
WHERE purchase.member _id = member_exclusio n.member_id_to_ exclude AND
purchase.member _id = 21101
)

////////////////////////////////////////////////////////

So I did an explain of this query, and I have the following result:

id select_type table type possible_keys
key key_len ref rows Extra
1 PRIMARY lead ALL exclusive,nb_pu rchases
NULL NULL NULL 4490 Using where
4 DEPENDENT SUBSELECT member_exclusio n index NULL
PRIMARY 16 NULL 3 Using where; Using index
4 DEPENDENT SUBSELECT purchase index member_id_purch ase_key
PRIMARY 12 NULL 11022 Using where; Using index
3 DEPENDENT SUBSELECT affiliate_locko ut ref PRIMARY
PRIMARY 8 const 2 Using where; Using index
2 DEPENDENT SUBSELECT purchase index member_id_purch ase_key
PRIMARY 12 NULL 11022 Using where; Using index
According to the documentation, it is a bad result, but I don't know
how to modify th database to get better (what index to add, ...)

Could somebody help me ? I really need to get a better result for my
work ...
krystoffff
Jul 19 '05 #1
0 1081

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

Similar topics

2
2070
by: Rachel Forder | last post by:
Hi All, I have a problem related to the sort function provided by STL. class A{ A(string, string, int); string itemA; string itemB; int itemC; };
2
1542
by: Viktor Elvar | last post by:
Hi there I have a strange problem. I developing an application on my server SQL Server 2000 which is running on a 1 Gb memory and 2 GHz W2000 advanched server. The app. it self is running on my local computer 400 Mhz 256 Mb memory and it running wery vell. But when I put the application up on a different environment the SQL Server runs on a...
2
1208
by: Greg Stark | last post by:
I have a query that is taking too long when run from a larger plpgsql function (40-50s). However when I explain analyze it under psql it runs fine (4-5s). This is with the same parameters, and I've even tried embedding the parameters inside a subquery to avoid letting the planner see any more info than normal. Is there any way to ask the...
3
1583
by: Net Virtual Mailing Lists | last post by:
Hello, I have a table like this with some indexes as identified: CREATE TABLE sometable ( data TEXT, data_fti TSVECTOR, category1 INTEGER, category2 INTEGER,
14
19649
by: Jeff | last post by:
This is the first time that I remember ever having too many indexes on a table, but it has happened. I have en employees table and store in many places, on tables, the id of the employee that performed some action. Yes, I know, that could be in an audit trail but it isn't. For example, who printed a sales order, who processed it etc is...
10
2680
by: lesperancer | last post by:
you start with a small application in access97, then you have more modules and more... and you reach the point where tables like 'item' and 'employee' reach the limit and you know there's more indexes required for RI to come does creating a RI programatically instead of the relationship window still consume one of the 32 indexes ? does...
9
5745
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just call it Express for simplicity). I have, to try to simplify things, put the exact same DB on two systems, one running MSDE and one running...
4
2062
by: Laurence Breeze | last post by:
I wonder if anyone can help ... Today I tried to create another non-clustered index on a table. This failed as I apparently already had 249 non-clustered indexex on the table. Looking at the definition of the table there were 90 or so indexes already defined and not 249. (For those of you who quite rightly think 90 indexes on a table is...
6
1750
by: DBMonitor | last post by:
I have a table on a database that contains 18million records. I need to design a system that queries this table to produce fast counts. I have got counts for multiple criteria down to only a few seconds. Most take under a second however I have a few queries that seam to take longer which I am working on reducing the time. I have found...
0
7544
MMcCarthy
by: MMcCarthy | last post by:
The more data you include in your tables the more you will need to have indexes to search and sort that data. However, there is a balance between having enough indexes and too many. Too many indexes will slow down the speed of updates on your records. Access presets a number of Indexes for you. If you look in Tools ... Options under the...
0
7726
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. ...
1
7485
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...
0
6052
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...
1
5377
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...
0
5097
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...
0
3505
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...
0
3488
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1953
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
1
1064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.