MemSQL中的MySQL PDO SELECT查询

时间:2019-07-20 10:02:17

标签: php mysql database pdo memsql

过去,我们使用MySQL作为您的数据库提供程序,但现在我们开始使用MemSQL,并且在php中使用PDO执行SELECT查询时遇到了一些问题。

以下是适用于MySQL的查询

$query = DB::getInstance()
    ->query("
        SELECT 
            topics.id as id,
            topics.forum_id as forum_id,
            topics.topic_title as topic_title,
            topics.topic_creator as topic_creator,
            topics.topic_last_user as topic_last_user,
            topics.topic_date as topic_date,
            topics.topic_reply_date as topic_reply_date,
            topics.topic_views as topic_views,
            topics.locked as locked,
            topics.sticky as sticky,
            topics.label as label,
            topics.deleted as deleted,
            posts.id as last_post_id
        FROM nl2_topics topics
        LEFT JOIN nl2_posts posts
          ON topics.id = posts.topic_id
          AND posts.id = (
            SELECT MAX(id)
            FROM nl2_posts p
            WHERE p.topic_id = topics.id 
              AND p.deleted = 0
          )
        WHERE topics.deleted = 0
          AND topics.forum_id IN " . $all_topics_forums_string . "
        ORDER BY topics.topic_reply_date DESC
        LIMIT 50
    ", array(), PDO::FETCH_ASSOC)
    ->results();

从MemSQL数据库中出现此错误

Uncaught PDOException: SQLSTATE[HY000]: General error: 1749 Feature 'Correlated subselect that can not be transformed and does not match on shard keys' is not supported by MemSQL Distributed. in /var/www/html/core/classes/DB.php:51
Stack trace:
#0 /var/www/html/core/classes/DB.php(51): PDOStatement->execute()
#1 /var/www/html/modules/Forum/classes/Forum.php(237): DB->query('SELECT topics.i...', Array, 2)
#2 /var/www/html/modules/Forum/pages/forum/index.php(71): Forum->getLatestDiscussions('2', Array, '1')
#3 /var/www/html/index.php(84): require('/var/www/html/m...')
#4 {main}
  thrown

错误指向我发送的查询。

0 个答案:

没有答案