简体   繁体   English

如何从mysql获取大数据

[英]How to fetch large data from mysql

Table Query:
Id     Subject    LangId    replyCount    created_at

Table userLogin:
Id     userId     Fname    Lanme    created_at

I am using select query with inner join to fetch data from mysql but it takes about 5sec to fetch 10000 records,I have also used indexing on coulmn LangId,Can you suggest any other way to make it run faster? 我正在使用带有内部联接的选择查询从mysql读取数据,但大约需要5秒才能读取10000条记录,我还对coulmn LangId使用了索引,您能否建议其他方法以使其运行更快?

select q.id,q.Subject,u.userid,q.replyCount,DATE_FORMAT(q.created_at,'%d-%b-%Y') 
from query as q INNER JOIN userLogin as u on q.userId = u.id where q.LangId = ?

Just do not select 10000 records at once. 只是不要一次选择10000条记录。

To do a pagination, you have to run the same query on the every page with LIMIT clause, fetching the only records required on the page. 要进行分页,您必须使用LIMIT子句在每个页面上运行相同的查询,仅获取页面上所需的记录。

Use paging if u have larg records, and if you have complex queries then make a view table, then simply fetch record from view with single select statement.. 如果您有较大的记录,请使用分页,如果您有复杂的查询,则创建一个视图表,然后仅使用单个select语句从视图中获取记录。

Hope you understand.. 希望你能理解..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM