"thinkphp" Table Relationmodel Query efficiency issues (1 Table 7 Table query efficiency)
This post was last edited by default7 on 2014-05-19 12:21:36
thinkphp version 3.1.3, do an information platform, similar to www.35dalu.com/info this site.
The table is as follows:
1) info (tid,title,uid,d1,d2,d3,c1,c2,c3,status,date1,date2)
2) member (UID,UNAME)
3) Cat (Id,name,level)
4) diqu (Id,name,level)
Correspondence Relationship:
Info.uid=member.uid
Info.d1=diqu.id & Diqu.level=1
Info.d2=diqu.id & diqu.level=2
Info.d3=diqu.id & Diqu.level=3
Info.c1=cat.id & Cat.level=1
Info.c2=cat.id & cat.level=2
Info.c3=cat.id & Cat.level=3
Now you need to query the list data, the main table info will be the table of the other 3 tables (in fact, 7 tables), with thinkphp relationaction.
by Default7#zbphp.com Index/info
$obj = D (' Info ');
$this->info = $obj->where (' Status=1 ')->order (' Date2 DESC ')->limit (->relation (True)->field (' Tid,title,d1,d2,uid ')->select ();
Dump ($obj->getlastsql ());
Dump (' Total SQL query count: '. N (' db_query ')); Actually SQL query how big 367 bar!
But found that the SQL executed is the following split-all operations, SQL records:
thinkphp implementation of the principle is to first query data in the Info table, and then use PHP to a query and then add the array in?
It is doubtful that this will not affect the efficiency very much? How to optimize queries? Can I define my own SQL query (by default7#zbphp.com)
------Solution--------------------
You recently tp problem more OH.