Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder student's Avatar
    Join Date
    Jan 2007
    Posts
    129
    Thanks
    13
    Thanked 0 Times in 0 Posts

    why is this query so slow?

    Hello,
    I have been trying to optimze my mysql database and set up 'index' on two columns. But still I am finding many slow queries in the log.
    for example,

    # Mon Mar 26 03:26:59 2007
    # Query_time: 8 Lock_time: 0 Rows_sent: 1 Rows_examined: 0
    use my_data;
    SELECT * FROM table WHERE (site = 'myourinbox') LIMIT 1

    # Mon Mar 26 03:36:25 2007
    # Query_time: 8 Lock_time: 0 Rows_sent: 10 Rows_examined: 1352
    use my_data;
    SELECT DISTINCT site FROM table WHERE category='business' ORDER BY popularity LIMIT 270, 10

    category is index.
    site is Unique key and also index.

    1) how to optimize these queries?

    2) can I have both Index and Unique on the same column?

    Thank you

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    without the table structure...i can only guess that ur table design is not normalized as u need distinct

  • #3
    Regular Coder student's Avatar
    Join Date
    Jan 2007
    Posts
    129
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by shyam View Post
    without the table structure...i can only guess that ur table design is not normalized as u need distinct
    $query = "CREATE TABLE table (
    id int(11) NOT NULL auto_increment,
    site varchar(12) NOT NULL default '',
    title varchar(200) default NULL,
    description text,
    keywords text,
    category varchar(100) default NULL,
    PRIMARY KEY (id),
    KEY category (category)
    )";

    after this I have added index on 'site' using wizmysqladmin script.

    what is wrong with this?
    and please inform me how to optimize queries.
    Thank you


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •