Hi help me with this interesting question.

Discussion in 'MySQL' started by Subikar, Dec 25, 2007.

  1. #1
    SELECT DISTINCT(ibf_posts.author_id), ibf_topics.* FROM ibf_topics LEFT JOIN ibf_posts ON (ibf_topics.tid=ibf_posts.topic_id AND ibf_posts.author_id=25869) WHERE ibf_topics.forum_id=4 and ibf_topics.approved=1 and (ibf_topics.pinned=1 or ibf_topics.last_post > 0) ORDER BY pinned DESC, last_post DESC LIMIT 0,30


    PLease suggest me the best possible optimize sql.


    Thanks in advance for any help.
    Subikar
     
    Subikar, Dec 25, 2007 IP
  2. InFloW

    InFloW Peon

    Messages:
    1,488
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    0
    #2

    Well first question would be do you have indexes on the following columns

    ibf_posts.topic_id
    ibf_posts.author_id
    ibf_topics.forum_id

    These could be indexed as well depending on the situation
    ibf_topics.approved
    ibf_topics.pinned



    But considering this is IBF maybe it's something to talk to them about if you're seeing slow query performance with this board as your database gets very large?
     
    InFloW, Dec 25, 2007 IP
  3. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Is indexing will help to make it faster. anything more I have to do in the table to change or any sql changes do I need ??


    Thanks,
    Subikar
     
    Subikar, Dec 26, 2007 IP
  4. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #4
    kmap, Dec 26, 2007 IP
  5. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Really thank you. I am weak in sql trying to do it myself. So that I can learn. Thank you very much :) I am doing if need any help will ask you.

    And if it successful I will let you know.

    Any more suggestion pls help me.

    Thanks,
    Subikar
     
    Subikar, Dec 26, 2007 IP
  6. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #6
    php and mysql is very good comination to start with and its not very tough.

    Donot think we know everything ,even i am still learning and its a continuous process.

    Google the info whatever you have ,try to read on forums,tutorial i know it will be difficult to start like this but this works!

    I wish you best of Luck and Happy New Year

    Regards

    Alex
     
    kmap, Dec 26, 2007 IP
  7. kendo1979

    kendo1979 Peon

    Messages:
    208
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    i'm not really an expert on optimization

    but let me try

    SELECT DISTINCT(ibf_posts.author_id), ibf_topics.* FROM ibf_topics LEFT JOIN ibf_posts ON (ibf_topics.tid=ibf_posts.topic_id AND ibf_posts.author_id=25869) WHERE ibf_topics.forum_id=4 and ibf_topics.approved=1 and (ibf_topics.pinned=1 or ibf_topics.last_post > 0) ORDER BY pinned DESC, last_post DESC LIMIT 0,30

    since the query already stated that you are looking for ibf_posts.author_id=25869

    so instead of using SELECT DISTINCT(ibf_posts.author_id) why not using SELECT only and rearrange the WHERE clause to

    SELECT ibf_topics.* FROM ibf_topics LEFT JOIN ibf_posts ON (ibf_topics.tid=ibf_posts.topic_id) WHERE ibf_topics.forum_id=4 and ibf_topics.approved=1 and ibf_posts.author_id=25869 and (ibf_topics.pinned=1 or ibf_topics.last_post > 0) ORDER BY pinned DESC, last_post DESC LIMIT 0,30
     
    kendo1979, Dec 26, 2007 IP
  8. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #8
    SELECT ibf_topics.* FROM ibf_topics LEFT JOIN ibf_posts ON (ibf_topics.tid=ibf_posts.topic_id) WHERE ibf_topics.forum_id=4 and ibf_topics.approved=1 and ibf_posts.author_id=25869 and (ibf_topics.pinned=1 or ibf_topics.last_post > 0) ORDER BY pinned DESC, last_post DESC LIMIT 0,30


    From this sql I am not getting the exact value what the previous sql I am getting. This your sql is returing the null value. :)

    I need more help from you.

    Thanks,
    Subikar
     
    Subikar, Dec 26, 2007 IP
  9. kendo1979

    kendo1979 Peon

    Messages:
    208
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    i think ibf_posts.author_id=25869 should not be set literally to ibf_posts.author_id=25869 since it should be dynamically stated by the script.

    could i see the real script portion?

    what type of value were you expecting?
     
    kendo1979, Dec 27, 2007 IP