小编ack*_*inc的帖子

Postgres 选择一个根据自己的估计更昂贵的查询计划

对于特定查询,我有以下 2 个查询计划(第二个是通过关闭 seqscan 获得的):

seqscan 已开启

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)

postgresql

5
推荐指数
1
解决办法
520
查看次数

这个"智能指针"代码会泄漏内存吗?

我想知道来自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 …

c++ memory memory-leaks

2
推荐指数
1
解决办法
81
查看次数

标签 统计

c++ ×1

memory ×1

memory-leaks ×1

postgresql ×1