【问题标题】:Bad N1QL performanceN1QL 性能不佳
【发布时间】:2016-07-27 10:06:39
【问题描述】:

我使用 N1QL 从我的 couchbase 数据库中读取数据并且遇到了非常糟糕的性能。我正在使用视图 atm,但如果有人知道为什么会发生这种情况,我很高兴知道,也许我会回到 N1QL。虽然 2M 记录的分页非常慢(但有效),但分页搜索超时 @ 2M 记录。 Couchbase CE 4.1.0

这里是查询:

public static function findByPage($recordsPerPage, $page) {
        $query = CouchbaseN1qlQuery::fromString('SELECT * FROM `public_portal` WHERE `collection`=$collection ORDER BY `_id` LIMIT $limit OFFSET $offset');
        $query->options['$collection'] = static::COLLECTION_NAME;       
        $query->options['$limit'] = $recordsPerPage;        
        $query->options['$offset'] = $recordsPerPage*($page-1);     
        return self::doQueryAndGetObjects($query);
    }

索引:

CREATE INDEX `public_portal_collection` ON `public_portal`(`collection`) USING GSI;

CREATE INDEX `public_portal_id` ON `public_portal`(`_id`) USING GSI;

我的解释:

cbq> EXPLAIN SELECT * FROM `public_portal` WHERE `collection`="tree" ORDER BY `_id` LIMIT 24 OFFSET 24;
{
    "requestID": "ab6df326-8f33-48b6-84a4-c22ac394f803",
    "signature": "json",
    "results": [
        {
            "#operator": "Sequence",
            "~children": [
                {
                    "#operator": "Sequence",
                    "~children": [
                        {
                            "#operator": "IndexScan",
                            "index": "public_portal_collection",
                            "keyspace": "public_portal",
                            "namespace": "default",
                            "spans": [
                                {
                                    "Range": {
                                        "High": [
                                            "\"tree\""
                                        ],
                                        "Inclusion": 3,
                                        "Low": [
                                            "\"tree\""
                                        ]
                                    }
                                }
                            ],
                            "using": "gsi"
                        },
                        {
                            "#operator": "Parallel",
                            "~child": {
                                "#operator": "Sequence",
                                "~children": [
                                    {
                                        "#operator": "Fetch",
                                        "keyspace": "public_portal",
                                        "namespace": "default"
                                    },
                                    {
                                        "#operator": "Filter",
                                        "condition": "((`public_portal`.`collection`) = \"tree\")"
                                    },
                                    {
                                        "#operator": "InitialProject",
                                        "result_terms": [
                                            {
                                                "expr": "self",
                                                "star": true
                                            }
                                        ]
                                    }
                                ]
                            }
                        }
                    ]
                },
                {
                    "#operator": "Order",
                    "sort_terms": [
                        {
                            "expr": "(`public_portal`.`_id`)"
                        }
                    ]
                },
                {
                    "#operator": "Offset",
                    "expr": "24"
                },
                {
                    "#operator": "Limit",
                    "expr": "24"
                },
                {
                    "#operator": "FinalProject"
                }
            ]
        }
    ],
    "status": "success",
    "metrics": {
        "elapsedTime": "6.755603ms",
        "executionTime": "6.573912ms",
        "resultCount": 1,
        "resultSize": 2972
    }
}

这是使用 4000x5 记录完成的。

“收藏”就是我所说的“类型”。

【问题讨论】:

    标签: php indexing couchbase n1ql


    【解决方案1】:

    查询使用order by,查询引擎需要在返回文档之前获取所有记录并排序,即使限制值很小,因为它需要时间。

    您看到的超时类型。是来自索引器还是查询。你能发布超时消息吗?

    在 4.5.0 中,这种类型的查询性能要好得多。

    【讨论】:

    • 由于某种原因它不再超时,它什么也不返回。没有 ORDER BY 会快一点,但我需要它。我等 4.5.0。
    猜你喜欢
    • 2016-05-17
    • 2011-01-03
    • 2016-11-06
    • 2019-06-15
    • 2013-06-11
    • 2010-12-31
    • 2012-01-25
    • 2021-12-15
    • 2011-02-13
    相关资源
    最近更新 更多