› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
daijia1123
V2EX  ›  MySQL

如果列出“节点收藏”中对应的主题,如何书写最有效率的 SQL?

  •  
  •   daijia1123 · May 11, 2015 · 3851 views
    This topic created in 4159 days ago, the information mentioned may be changed or developed.
    当前节点收藏中是列出收藏的节点,点击节点后才能查看相应主题。
    如果想进入后,直接按时间顺序列出收藏节点的相应主题该如何做最有效率?SELECT * FROM Topics WHERE id IN (SELECT id FROM nodes WHERE userid=uid),这种方式感觉效率不会高。
    数据库结构是否也有特别需要注意的地方(除了索引等)?
    3 replies  •  2015-05-11 17:31:16 +08:00
    anoymoux
        1
    anoymoux  
       May 11, 2015   ❤️ 1
    SELECT * FROM Topics t,nodes n WHERE t.id =n.id and n.userid=uid
    anoymoux
        2
    anoymoux  
       May 11, 2015   ❤️ 1
    SELECT t.* FROM Topics t,nodes n WHERE t.id =n.id and n.userid=uid
    fangjinmin
        3
    fangjinmin  
       May 11, 2015   ❤️ 1
    设计上没有什么问题。问题是你用了子查询,一般来说不会快。这样会好一些,select * from topics join nodes on (topics.id = nodes.id) where nodes.userid=uid,然后nodes的userid和id都加上索引。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2930 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 12:52 · PVG 20:52 · LAX 05:52 · JFK 08:52
    ♥ Do have faith in what you're doing.