MySql - slow sending data phase

前端 未结 6 1151
醉话见心
醉话见心 2020-12-14 01:03

One of my queries on MySQL 5.0.45 is running slow in \"sending data\" phase. The query is a simple select, returns about 300 integer ID fields as result set.

mysq         


        
相关标签:
6条回答
  • 2020-12-14 01:20

    I experienced this after moving from MySQL 5.5.x to 5.7.x. My query using joins was fast on MySQL 5.5 and really slow on MySQL 5.7.

    The problem was that MySQL 5.7 chose another set of indexes than MySQL 5.5 did.

    Adding USE INDEX fixed the issue.

    0 讨论(0)
  • 2020-12-14 01:22

    You could probably look at hardware part of mysql server. As Mysql doc says:

    Sending data

    The thread is reading and processing rows for a SELECT statement, and sending data to the client. Because operations occurring during this this state tend to perform large amounts of disk access (reads), it is often the longest-running state over the lifetime of a given query.

    So, if your server has slow disk I/O due to huge db/table file or disabled tableperfile InnoDB option/fragmentation/incorrectly configured RAID/disk crash process started (wait for soon disk death)/any other reason of disk I/O slowness - it could be reason for dramatically increased "Sending data" step as at this stage server gathering all requested data from disk and sends it to client.

    Of course you should try to optimize select to use indexes first and make sure this is not programming issue as this affects this stage time in most cases.

    0 讨论(0)
  • 2020-12-14 01:23

    I had the same issue: Send Data was very slow, but I had the correct indexes etc.

    After much digging around, I found that my join was comparing two fields that were indexed, but had different Collation - one was latin1_swedish_ci and the other was uft8_general_ci.

    Once I sent them both to utf8 the query was significantly faster (from 2.7 seconds to 0.002 seconds)

    0 讨论(0)
  • 2020-12-14 01:26

    I had two index (date_index and id) ,

    i had WHERE date_index>NOW() - INTERVAL 24 HOURS and an ORDER BY id in query, MySql preferred id as index and it didn't use date_index that caused long query time for big tables.

    i found it in a legacy system after 5 years that tables was grown.

    0 讨论(0)
  • 2020-12-14 01:37

    Your query spends 2.127019 to execute the query. This is probably because you have a large amount of data, and your are missing an index on the destination_id column. Try :

    CREATE INDEX index_destination_id ON directions (destination_id);

    Then your request will run smoothly.

    0 讨论(0)
  • 2020-12-14 01:45

    An explain-plan is usually the best place to start whenever you have a slow query. To get one, run

    DESCRIBE SELECT source_id FROM directions WHERE (destination_id = 10);
    

    This will show you a table listing the steps required to execute your query. If you see a large value in the 'rows' column and NULL in the 'key' column, that indicates that your query having to scan a large number of rows to determine which ones to return.

    In that case, adding an index on destination_id should dramatically speed your query, at some cost to insert and delete speed (since the index will also need to be updated).

    0 讨论(0)
提交回复
热议问题