jmoiron / sqlx

general purpose extensions to golang's database/sql
http://jmoiron.github.io/sqlx/
MIT License
16.24k stars 1.08k forks source link

use sqlx query takes longer than execute sql command in mysql #372

Open kingeasternsun opened 6 years ago

kingeasternsun commented 6 years ago

this is output of software using sqlx,takes 1.513185157s :

2017/12/09 09:40:59 |DEBUG||quickmysql.go|queryProduceReportListOfDidFromDb()|69| select mac ,result,processname,processnum,processid,report
time,userid from mytable where mac = 'c4430d70c66d' and orderid = 'orderid142'
2017/12/09 09:41:01 |DEBUG||quickmysql.go|queryProduceReportListOfDidFromDb()|78|1.513185157s

execute the same command in mysql, only takes 0.02754125s ( to avoid the cache, another test use different mac ,but both have same rows in the table)

mysql> show profiles;
|        4 | 0.02754125 | select sql_no_cache mac as did,result,processname,processnum,processid,reporttime,userid from mytable where mac = 'c4430d70c66c' and orderid = 'orderid142' |

the table totally has 1598321 rows,and the query result above has 183 results.

jmoiron commented 6 years ago

Hello!

Are you able to share more information?

Particularly, it would be useful if you could produce a fast result with database/sql + your driver that is also a slow result in sqlx. There is very little that sqlx does on the actual query execution path, so problems like these are usually to do with configuration, query execution plans, or the driver layer.

kingeasternsun commented 6 years ago

thx for your reply, 1 they are the same databases

  1. they have the same number of rows and i tried the driver gomysql ,it got the same result of sqlx, so i' will check something other code to find the reason.