"thinkphp" table Relationmodel query Efficiency related issues (1 Table 7 Table query efficiency related issues)

Source: Internet
Author: User
"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.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.