N1ql需要很长时间才能执行

时间:2018-09-05 08:24:10

标签: n1ql

Leak_DefinitelyLost
vg_replace_malloc.c
240 bytes in 10 blocks are definitely lost in loss record 1 of 1
    operator new(unsigned long)
    __gnu_cxx::new_allocator<double>::allocate(unsigned long, void const*)
    std::allocator_traits<std::allocator>::allocate(std::allocator<double>&, unsigned long)
    std::_Vector_base<double, std::allocator>::_M_allocate(unsigned long)
    std::_Vector_base<double, std::allocator>::_M_create_storage(unsigned long)
    std::_Vector_base<double, std::allocator>::_Vector_base(unsigned long, std::allocator<double> const&)
    std::vector<double, std::allocator>::vector(std::vector<double, std::allocator> const&)
    Derived_A::Derived_A(double, std::vector<double, std::allocator>, std::vector<double, std::allocator>)
    std::_MakeUniq<Derived_A>::__single_object std::make_unique<Derived_A, int&, std::vector, std::vector>(int&, std::vector<double, std::allocator>&&, std::vector<double, std::allocator>&&)
    main

上面的查询需要很长时间才能执行,您能否建议此查询使用合适的索引。

3 个答案:

答案 0 :(得分:0)

首先要尝试的是在a.dtype上建立索引:

CREATE INDEX dtype_idx ON pricing_qa_2(dtype)

我不明白为什么您的查询中有一个1 = 1子句,但是您应该删除它。

答案 1 :(得分:0)

以下索引和查询组合应使用索引顺序,以避免排序和由于排序而导致的额外提取。结帐说明。

CREATE INDEX ix1 ON pricing_qa_2(LOWER(sch_name), aud_info.ts DESC) WHERE dtype = "qqcfxspd";

SELECT a.*, META(a).id 
FROM  `pricing_qa_2`  AS a 
WHERE a.dtype = "qqcfxspd" AND LOWER(sch_name) IS NOT NULL
ORDER BY LOWER(sch_name) ASC, aud_info.ts DESC 
OFFSET 0 
LIMIT 24;

OR

CREATE INDEX ix1 ON pricing_qa_2(dtype, LOWER(sch_name), aud_info.ts DESC);

SELECT a.*, META(a).id 
FROM  `pricing_qa_2`  AS a 
WHERE a.dtype = "qqcfxspd" 
ORDER BY LOWER(sch_name) ASC, aud_info.ts DESC 
OFFSET 0 
LIMIT 24;

答案 2 :(得分:0)

感谢您的建议Johan和vsr提供了很多帮助。 创建以下索引并在查询中进行较小的更改后,我能够在毫秒内获得结果。

REATE INDEX ix1 ON pricing_qa_2(LOWER(sch_name), aud_info.ts DESC) WHERE dtype = "qqcfxspd";

SELECT *, META().id FROM `pricing_qa_2` 
WHERE dtype = "qqcfxspd"  AND lower(sch_name) is not missing and aud_info.ts is not missing 
ORDER BY LOWER(ch_name) , aud_info.ts DESC  OFFSET 0 limit 24