dougu4448 2015-04-25 14:23
浏览 45

使用ORM从远程数据库查询(即Eloquent)

I have recently come across a situation where querying from two tables that has about 16k records each.

Executing raw SQL results in the response time to a few seconds and if I opt to stick to the ORM queries, the same results in a nginx request timeout since the query takes more than 1 min to process.

Has anyone faced a similar scenario , I am aware that heavy queries can be made using a Doctrine.

The implementation looks like this. A more detailed explanation on the architecture that is in use: https://stackoverflow.com/a/19771835/540771

Laravel App Default Connection connects to DB 1 (has connection details to DB 2). According to the correct connection connects to appropriate DB.

DB 1:

connections table ( id, db_name, db_username, db_password, hostname, port)

DB 2:

customer ( customer_id, name )
customer_details ( customer_id, email, etc ... ) 

The query executes on the DB 2 and looks like:

SELECT * 
FROM customers as c LEFT JOIN customer_details as cd 
ON c.customer_id=cd.customer_id
ORDER BY c.created_at DESC

The row count on the table customers and customer details is 16k each. The relationship is 1 .. * , but the business rules limit it in a way so that there is always 1 customer record maps into 1 customer_details record.

The result that is fetched into a Datatable. Pagination is to be added to limit the number of records returned.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭