1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Slow Query When Using Union All

Discussion in 'MySQL' started by qeghut, Feb 10, 2013.

  1. #1
    Hi,
    mysql query is extremely slow when I use SELECT ... UNION ALL ... SELECT for one table.
    Queries on that table are working fine when I use only SELECT.
    There are other tables on the same database some of them are larger of that table but UNION ALL works fast for them. Only for one table and when using UNION ALL in the query.
    Any help would be greatly appreciated.
     
    qeghut, Feb 10, 2013 IP
  2. Ratty

    Ratty Active Member

    Messages:
    565
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    95
    Digital Goods:
    1
    #2
    Have you made sure you have the right indexes on your tables you are selecting from?
     
    Ratty, Feb 10, 2013 IP
  3. qeghut

    qeghut Greenhorn

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    well I'm not sure ... but I had not changed anything, it started working slow suddenly.
    The same query works fast ...
    let's say SELECT * FROM table1 this works fast
    and SELECT * FROM table2 works fine too
    but
    SELECT * FROM table1
    UNION ALL
    SELECT * FROM table2
    this works extremely slow



    there are other tables on which it's fast as well
    SELECT * FROM table2
    UNION ALL
    SELECT * FROM table3
     
    qeghut, Feb 10, 2013 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    Are the field types of table1 and table 2 identically the same? (If it's the same table, you shouldn't be using different names for it.)
     
    Rukbat, Feb 12, 2013 IP