// Query all logs $ SQL = "SELECT c1. *, c2. * FROM log c1 LEFT JOIN log_time c2 ON (c1.time _ id = c2.tid) WHERE c2.year = '". $ year. "'AND c1.userid = '". $ u ['uid']. "'AND c2.end _ date <'". date ("Y-m-d "). "'Order BY c2.tid desc "; $ Query = $ db-> query ($ SQL ); While ($ row = $ db-> fetch_array ($ query )){ ?>
The index is created, and the result does not work at all. If ?? No ??? Can be used? Save. For example: $ Data = getcache ();//?? Saving? Fetch If ($ data = ''){ //? Db? Take ?? $ Data = '? Db? '; Setcache ($ data );//? Incoming? Storage } Echo $ data; Check whether the index is used, Minimize the amount of content that does not need to be queried, or minimize the number of items that need to be queried at a time.
Explain your SQL statement to check the index usage
You can store data in files or memcache. However, you cannot query in a loop. You can query and recycle all the data in two tables at a time, which may be faster than the current one. The nested loop query is terrible. In my opinion, the nested loop query efficiency is very low. we recommend that you merge it. Optimize the SQL statement. try to find all the content in one SQL statement, and then demonstrate it cyclically below. Association: Department table associated user table associated log table associated audit table Sort: first sort by Department id, then by user id, then... (the relationship behind is not clear) Condition: those of you. integrate them. Query field: used only, such as Department id, department name, user id, user name) Number of queries: You do not have one. we recommend that you write one. it is terrible to query big data without paging. In this way, only one statement can be used to obtain data. The next step is to traverse the data. The data is sorted in ascending order, so you don't have to worry about chaos. First, traverse the department. if the department id is different, create another table. Each department traverses the user and creates another table if the user is different. Every user... I don't know if the following SQL statement can speed you up (it is not guaranteed that the SQL statement is correct and feasible) SELECT d. *, m. *, l. * FROM depart d Left join members m on m. flag <5 and m. groupid = d. gid Left join (SELECT c1. *, c2. * FROM log c1 left join log_time c2 ON (c1.time _ id = c2.tid) WHERE c2.year = '". $ year. "'AND c2.end _ date <'". date ("Y-m-d "). "') l on l. userid = m. uid WHERE d. gid> 0 AND d. gid <15 order by d. gid, m. flag desc, l. tid desc Written as a statement ~ Desc SQL Create an index using the keyword field
If ?? No ??? Can be used? Save. For example: $ Data = getcache ();//?? Saving? Fetch If ($ data = ''){ //? Db? Take ?? $ Data = '? Db? '; Setcache ($ data );//? Incoming? Storage } Echo $ data; If ?? No ??? Can be used? Save. For example: $ Data = getcache ();//?? Saving? Fetch If ($ data = ''){ //? Db? Take ?? $ Data = '? Db? '; Setcache ($ data );//? Incoming? Storage } Echo $ data; I don't know if the following SQL statement can speed you up (it is not guaranteed that the SQL statement is correct and feasible) SELECT d. *, m. *, l. * FROM depart d Left join members m on m. flag <5 and m. groupid = d. gid Left join (SELECT c1. *, c2. * FROM log c1 left join log_time c2 ON (c1.time _ id = c2.tid) WHERE c2.year = '". $ year. "'AND c2.end _ date <'". date ("Y-m-d "). "') l on l. userid = m. uid WHERE d. gid> 0 AND d. gid <15 order by d. gid, m. flag desc, l. tid desc Association: Department table associated user table associated log table associated audit table Sort: first sort by Department id, then by user id, then... (the relationship behind is not clear) Condition: those of you. integrate them. Query field: used only, such as Department id, department name, user id, user name) Number of queries: You do not have one. we recommend that you write one. it is terrible to query big data without paging. In this way, only one statement can be used to obtain data. The next step is to traverse the data. The data is sorted in ascending order, so you don't have to worry about chaos. First, traverse the department. if the department id is different, create another table. Each department traverses the user and creates another table if the user is different. Every user...
|
|
Reply to discussion (solution) Is this written to a file?Is there a complete instance for your reference? Is this written to a file?Is there a complete instance for your reference? Yes? In the file. Http://www.itstrike.cn/Question/PHP-technology-to-achieve-dynamic-cache-instance I tried it. the query efficiency is fast, so I don't need to wait. but how can I call it on the page? My requirement is to first display the department, then all users in the department, and so on. But now it is displayed together with departments, users, and others. First, traverse the department. if the department id is different, create another table.Each department traverses the user and creates another table if the user is different. What does it mean to create another table with different IDs?
|