首页 > 解决方案 > Cassandra 数据统计 | 超时异常

问题描述

我对 cassandra 有疑问,我有以下错误。我链接图片

代码语法:

 public function find($db_table = null, $db_id = null) {
        $filter = "";
        $return = array();

        $cluster = $this->cluster();
        $session = $cluster->connect($this->keyspace);

        if(isset($db_table)) {
            $filter .= " WHERE db_table like '%".$db_table."%' ";

            if($db_id != null) {
                $filter .= " AND db_id = '".$db_id."' ALLOW FILTERING";
            }
        }

        $query  = new Cassandra\SimpleStatement("SELECT * FROM ".$this->keyspace.".log $filter;");
        $result = $session->executeAsync($query);
        $rows   = $result->get();

Cassandra 错误图片

标签: phpcassandradatastax

解决方案


  1. 除非您知道自己在做什么,否则不应使用“允许过滤”。
  2. SELECT * FROM prod.log WHERE db_id = 13913 AND db_table LIKE '%%' product LIMIT 5000 超时,因为您似乎在数据库中有很多条目并且允许过滤正在执行全表扫描。
  3. 您应该调整表设计以匹配您的查询。

推荐阅读