*/
void
vac_update_relstats(Relation relation,
- BlockNumber num_pages, double num_tuples,
+ BlockNumber num_pages,
+ double num_tuples,
BlockNumber num_all_visible_pages,
bool hasindex, TransactionId frozenxid,
MultiXactId minmulti,
*/
static int
get_remote_relstat(char *nspname, char *relname, bool replicated,
- int32 *pages, float4 *tuples, TransactionId *frozenXid)
+ int32 *pages, int32 *allvisiblepages,
+ float4 *tuples, TransactionId *frozenXid)
{
StringInfoData query;
EState *estate;
TupleTableSlot *result;
int validpages,
validtuples,
- validfrozenxids;
+ validfrozenxids,
+ validallvisiblepages;
/* Make up query string */
initStringInfo(&query);
appendStringInfo(&query, "SELECT c.relpages, "
"c.reltuples, "
+ "c.relallvisible, "
"c.relfrozenxid "
"FROM pg_class c JOIN pg_namespace n "
"ON c.relnamespace = n.oid "
make_relation_tle(RelationRelationId,
"pg_class",
"reltuples"));
+ step->scan.plan.targetlist = lappend(step->scan.plan.targetlist,
+ make_relation_tle(RelationRelationId,
+ "pg_class",
+ "relallvisible"));
step->scan.plan.targetlist = lappend(step->scan.plan.targetlist,
make_relation_tle(RelationRelationId,
"pg_class",
MemoryContextSwitchTo(oldcontext);
/* get ready to combine results */
*pages = 0;
+ *allvisiblepages = 0;
*tuples = 0.0;
*frozenXid = InvalidTransactionId;
validpages = 0;
+ validallvisiblepages = 0;
validtuples = 0;
validfrozenxids = 0;
result = ExecRemoteQuery(node);
validtuples++;
*tuples += DatumGetFloat4(value);
}
- value = slot_getattr(result, 3, &isnull); /* relfrozenxid */
+ value = slot_getattr(result, 3, &isnull); /* relallvisible */
+ if (!isnull)
+ {
+ validallvisiblepages++;
+ *allvisiblepages += DatumGetInt32(value);
+ }
+ value = slot_getattr(result, 4, &isnull); /* relfrozenxid */
if (!isnull)
{
/*
if (validtuples > 0)
*tuples /= validtuples;
+
+ if (validallvisiblepages > 0)
+ *allvisiblepages /= validallvisiblepages;
}
if (validfrozenxids < validpages || validfrozenxids < validtuples)
char *relname;
/* fields to combine relation statistics */
int32 num_pages;
+ int32 num_allvisible_pages;
float4 num_tuples;
TransactionId min_frozenxid;
bool hasindex;
* returning correct stats.
*/
rel_nodes = get_remote_relstat(nspname, relname, replicated,
- &num_pages, &num_tuples, &min_frozenxid);
+ &num_pages, &num_allvisible_pages,
+ &num_tuples, &min_frozenxid);
if (rel_nodes > 0)
{
int nindexes;
/* Fetch index stats */
for (i = 0; i < nindexes; i++)
{
- int32 idx_pages;
+ int32 idx_pages, idx_allvisible_pages;
float4 idx_tuples;
TransactionId idx_frozenxid;
int idx_nodes;
nspname = get_namespace_name(RelationGetNamespace(Irel[i]));
/* Index is replicated if parent relation is replicated */
idx_nodes = get_remote_relstat(nspname, relname, replicated,
- &idx_pages, &idx_tuples, &idx_frozenxid);
+ &idx_pages, &idx_allvisible_pages,
+ &idx_tuples, &idx_frozenxid);
if (idx_nodes > 0)
{
/*
vac_update_relstats(onerel,
(BlockNumber) num_pages,
(double) num_tuples,
- visibilitymap_count(onerel),
+ num_allvisible_pages,
hasindex,
min_frozenxid,
InvalidMultiXactId,
SELECT unique1 FROM tenk1
WHERE unique1 IN (1,42,7)
ORDER BY unique1;
- QUERY PLAN
--------------------------------------------------------------------------
+ QUERY PLAN
+-------------------------------------------------------------
Remote Subquery Scan on all (datanode_1,datanode_2)
- -> Sort
- Sort Key: unique1
- -> Bitmap Heap Scan on tenk1
- Recheck Cond: (unique1 = ANY ('{1,42,7}'::integer[]))
- -> Bitmap Index Scan on tenk1_unique1
- Index Cond: (unique1 = ANY ('{1,42,7}'::integer[]))
-(7 rows)
+ -> Index Only Scan using tenk1_unique1 on tenk1
+ Index Cond: (unique1 = ANY ('{1,42,7}'::integer[]))
+(3 rows)
SELECT unique1 FROM tenk1
WHERE unique1 IN (1,42,7)
Hash Cond: (a.hundred = b.thousand)
-> Remote Subquery Scan on all (datanode_1,datanode_2)
Distribute results by H: hundred
- -> Seq Scan on tenk1 a
+ -> Index Only Scan using tenk1_hundred on tenk1 a
-> Hash
-> Remote Subquery Scan on all (datanode_1,datanode_2)
Distribute results by H: thousand
execute foo(true);
count
-------
- 10998
+ 10000
(1 row)
execute foo(false);
explain (num_nodes off, nodes off, costs off)
select count(*) from tenk1 a,
tenk1 b join lateral (values(a.unique1)) ss(x) on b.unique2 = ss.x;
- QUERY PLAN
-------------------------------------------------------------------
+ QUERY PLAN
+------------------------------------------------------------------------------
Aggregate
-> Remote Subquery Scan on all
-> Aggregate
- -> Hash Join
- Hash Cond: (a.unique1 = b.unique2)
- -> Seq Scan on tenk1 a
- -> Hash
- -> Remote Subquery Scan on all
- Distribute results by H: unique2
- -> Seq Scan on tenk1 b
-(10 rows)
+ -> Merge Join
+ Merge Cond: (b.unique2 = a.unique1)
+ -> Remote Subquery Scan on all
+ Distribute results by H: unique2
+ -> Index Only Scan using tenk1_unique2 on tenk1 b
+ -> Index Only Scan using tenk1_unique1 on tenk1 a
+(9 rows)
select count(*) from tenk1 a,
tenk1 b join lateral (values(a.unique1)) ss(x) on b.unique2 = ss.x;
explain (num_nodes off, nodes off, costs off)
select count(*) from tenk1 a,
tenk1 b join lateral (values(a.unique1),(-1)) ss(x) on b.unique2 = ss.x;
- QUERY PLAN
------------------------------------------------------
+ QUERY PLAN
+------------------------------------------------------------------------
Aggregate
-> Hash Join
Hash Cond: ("*VALUES*".column1 = b.unique2)
-> Nested Loop
-> Remote Subquery Scan on all
- -> Seq Scan on tenk1 a
+ -> Index Only Scan using tenk1_unique1 on tenk1 a
-> Values Scan on "*VALUES*"
-> Hash
-> Remote Subquery Scan on all
- -> Seq Scan on tenk1 b
+ -> Index Only Scan using tenk1_unique2 on tenk1 b
(10 rows)
select count(*) from tenk1 a,
select thousand, tenthous from tenk1
where (thousand, tenthous) >= (997, 5000)
order by thousand, tenthous;
- QUERY PLAN
------------------------------------------------------------------------------
+ QUERY PLAN
+-----------------------------------------------------------------
Remote Subquery Scan on all (datanode_1,datanode_2)
- -> Sort
- Sort Key: thousand, tenthous
- -> Bitmap Heap Scan on tenk1
- Recheck Cond: (ROW(thousand, tenthous) >= ROW(997, 5000))
- -> Bitmap Index Scan on tenk1_thous_tenthous
- Index Cond: (ROW(thousand, tenthous) >= ROW(997, 5000))
-(7 rows)
+ -> Index Only Scan using tenk1_thous_tenthous on tenk1
+ Index Cond: (ROW(thousand, tenthous) >= ROW(997, 5000))
+(3 rows)
select thousand, tenthous from tenk1
where (thousand, tenthous) >= (997, 5000)
SubPlan 1
-> Remote Subquery Scan on all (datanode_1,datanode_2)
Output: a.unique1
- -> Seq Scan on public.tenk1 a
+ -> Index Only Scan using tenk1_unique1 on public.tenk1 a
Output: a.unique1
-> Materialize
Output: b.ten