My table structure is the same, the amount of data about the same, that is to say, in the same statement select * from SHSE_000905_min order by updatetime desc limit 500 query a table and query twice by two different tables vary widely on the time consuming, is this why?
The code is as follows:
MYSQL_ROW m_row;
MYSQL_RES * m_res=NULL;//data result set
Time_t t1, t2;
T1=time (NULL);
String sql1="select * from (select * from";
String sql2="order by updatetime desc limit";
String sql3=") a ORDER BY updatetime; ";
String SQL;
DataMin data;
for (int i=0; SymList [I]!=NULL; I++) {
//cout & lt; String SQLTB=symList [I];
Int id=SQLTB. Find (". ");
SQLTB [id]='_'.
SQL=sql1 + SQLTB + dType + sql2 + "500" + sql3;
//SQL=sql1 + "shse_600519_min + sql2 +", "500" + sql3;
Mysql_query (& amp; Mysql, SQL. C_str ());
M_res=mysql_store_result (& amp; Mysql);
While (m_row=mysql_fetch_row (m_res)) {
}
The mysql_free_result (m_res);
}
T2=time (NULL);
Printf (" running time is: % ld, "t2 - t1);
This is the query I table (a total of nearly 3000 tables), the running time of more than 70 seconds.
MYSQL_ROW m_row;
MYSQL_RES * m_res=NULL;//data result set
Time_t t1, t2;
T1=time (NULL);
String sql1="select * from (select * from";
String sql2="order by updatetime desc limit";
String sql3=") a ORDER BY updatetime; ";
String SQL;
DataMin data;
for (int i=0; SymList [I]!=NULL; I++) {
//cout & lt; String SQLTB=symList [I];
Int id=SQLTB. Find (". ");
SQLTB [id]='_'.
//SQL=sql1 + SQLTB + dType + sql2 + "500" + sql3;
SQL=sql1 + "shse_600519_min + sql2 +", "500" + sql3;
Mysql_query (& amp; Mysql, SQL. C_str ());
M_res=mysql_store_result (& amp; Mysql);
While (m_row=mysql_fetch_row (m_res)) {
}
The mysql_free_result (m_res);
}
T2=time (NULL);
Printf (" running time is: % ld, "t2 - t1);
This is a repeat query a table, query 3000 times, running time is four seconds,
CodePudding user response:
The following content is for reference only:On the premise of file size is the same:
Read just read files faster than first read didn't read the file
Fast reading speed of files on the hard drive is faster than reading speed slow hard disk file
Read no file disk fragments than there are fragments of disk files fast
Read the file does not handle faster than reading while processing
Single thread from the beginning to the end once read documents faster than multi-threaded read file each part respectively (SSD)
Read solid-state hard disk files faster than read common hard disk files
CodePudding user response:
Because the mysql open a table is the consumption of resources and time,
Just operating table, mysql will cache (similar to pressure the stack), if the query this repeatedly, mysql can immediately get the table () is obtained by the stack immediately,
Press the stack is arguably the most computer access to the data of the fastest way,
But if you want to change a table, it will affect the cache sequence, if the continuous changing table, mysql will be busy with the cache of the original, find and open up new, cache the original again, must be very time-consuming,