对于特定查询,我有以下 2 个查询计划(第二个是通过关闭 seqscan 获得的):
第二个计划的成本估算低于第一个计划,但是,pg 仅在被迫时才选择第二个计划(通过关闭 seqscan)。
什么可能导致这种行为?
编辑:用评论中请求的信息更新问题:
查询 1的输出EXPLAIN (ANALYZE, BUFFERS, VERBOSE)
(seqscan 开启;不使用索引)。也可在https://explain.depesz.com/s/cGLY查看:
QUERY PLAN
Limit (cost=2449.76..840962.24 rows=1 width=87) (actual time=25701.021..26540.060 rows=10 loops=1)
Output: books.id, books.title, books.authors, books.meta
Buffers: shared hit=2254959
-> Nested Loop Left Join (cost=2449.76..840962.24 rows=1 width=87) (actual time=25289.899..26128.923 rows=10 loops=1)
Output: books.id, books.title, books.authors, books.meta
Join Filter: (photos."bookId" = books.id)
Rows Removed by Join Filter: 62876457
Filter: (photos.id IS NULL)
Rows Removed by Filter: 707
Buffers: shared hit=2254959
-> Gather …
Run Code Online (Sandbox Code Playgroud) 我想知道来自Accelerated C++ Section 14.1.2的代码是否会在fn
调用时导致内存泄漏:
class IntPtr {
public:
IntPtr (): p(NULL) {};
IntPtr (int *ip): p(ip) {};
IntPtr (const IntPtr& other) { p = new int(*other.p); };
IntPtr& operator= (const IntPtr&);
~IntPtr () { delete p; };
private:
int *p;
}
IntPtr& IntPtr::operator= (const IntPtr& other) {
if (&other != this) { delete p; p = new int(*other.p); }
return *this;
}
void fn () {
IntPtr a;
a = new int(9);
}
Run Code Online (Sandbox Code Playgroud)
这是我认为a = new …