Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 优化SQL连接查询_Mysql_Sql - Fatal编程技术网

Mysql 优化SQL连接查询

Mysql 优化SQL连接查询,mysql,sql,Mysql,Sql,我有两个数据库表“friends”和“published_post” `friends` --- contains 650K rows -------------------------------------------------------- | fb_id_user(bigint) | fb_id_friend(bigint) | fb_username(text) | -------------------------------------------------------

我有两个数据库表“friends”和“published_post”

`friends` --- contains 650K rows 
--------------------------------------------------------
| fb_id_user(bigint)  |   fb_id_friend(bigint) | fb_username(text) |
---------------------------------------------------------


`published_post` ----- contains 6K rows
-------------------------------------------------------------------------------
| id(primary_key)(int)  |   fb_id(bigint) | post(text) |  post_date(DATE_TIME) |
-------------------------------------------------------------------------------
假设用户具有facebook id“12345”。我想按“发布时间”的降序获得他的朋友(从fb\u id\u user='12345')提供的所有帖子(
表单发布的帖子表
)。
任何关于如何有效执行此查询的建议都将非常有用。

代码使用反引号,因此我删除了SQL Server标记。代码使用反引号,因此我删除了SQL Server标记。代码使用反引号,因此我删除了SQL Server标记。代码使用反引号,因此我删除了SQL Server标记。
SELECT
    pp.*
FROM published_post pp
LEFT JOIN friends f ON f.fb_id_user = pp.fb_id
WHERE pp.fb_id_friend = '12345'
ORDER BY f.post_date DESC