Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the ability to create a non-distributed table (can be used for postgres extensions) #645

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/backend/parser/gram.y
Original file line number Diff line number Diff line change
Expand Up @@ -6046,6 +6046,15 @@ DistributedBy: DISTRIBUTED BY '(' distributed_by_list ')'
distributedBy->keyCols = NIL;
$$ = (Node *)distributedBy;
}
| DISTRIBUTED LOCAL
{
DistributedBy *distributedBy = makeNode(DistributedBy);
distributedBy->ptype = POLICYTYPE_LOCAL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we did choose POLICYTYPE_LOCAL Instead of POLICYTYPE_ENRTY, because getPolicyForDistributedBy explicitly forbits creating relation with POLICYTYPE_ENRTY policy. We are unaware of reason however.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible we keep distributeBy as NULL like pg_class? So that planner could work properly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will think about that

distributedBy->numsegments = -1;
distributedBy->keyCols = NIL;
$$ = (Node *)distributedBy;

}
;

OptDistributedBy: DistributedBy
Expand Down
6 changes: 6 additions & 0 deletions src/backend/parser/parse_utilcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2417,6 +2417,9 @@ transformDistributedBy(ParseState *pstate,
ListCell *lc;
int numsegments;

if(distributedBy->ptype == POLICYTYPE_LOCAL){
return distributedBy;
}
/*
* utility mode creates can't have a policy. Only the QD can have policies
*/
Expand Down Expand Up @@ -3134,6 +3137,9 @@ getPolicyForDistributedBy(DistributedBy *distributedBy, TupleDesc tupdesc)

case POLICYTYPE_REPLICATED:
return createReplicatedGpPolicy(distributedBy->numsegments);

case POLICYTYPE_LOCAL:
return NULL;
}
elog(ERROR, "unrecognized policy type %d", distributedBy->ptype);
return NULL;
Expand Down
3 changes: 2 additions & 1 deletion src/include/catalog/gp_distribution_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ typedef enum GpPolicyType
{
POLICYTYPE_PARTITIONED, /* Tuples partitioned onto segment database. */
POLICYTYPE_ENTRY, /* Tuples stored on entry database. */
POLICYTYPE_REPLICATED /* Tuples stored a copy on all segment database. */
POLICYTYPE_REPLICATED, /* Tuples stored a copy on all segment database. */
POLICYTYPE_LOCAL /* Tuples stored on coordinator */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the new policy type, is it any different from POLICYTYPE_ENTRY?

} GpPolicyType;

/*
Expand Down
9 changes: 9 additions & 0 deletions src/test/regress/expected/local_distribution.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Creates db on coordinator shard without distributing
CREATE TABLE local_table (asd Int) DISTRIBUTED LOCAL;
EXPLAIN SELECT * FROM local_table;
QUERY PLAN
----------------------------------------------------------------
Seq Scan on local_table (cost=0.00..106.30 rows=9630 width=4)
Optimizer: Postgres query optimizer
(2 rows)

1 change: 1 addition & 0 deletions src/test/regress/parallel_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# By convention, we put no more than twenty tests in any one parallel group;
# this limits the number of connections needed to run the tests.
# ----------
test: local_distribution

# run tablespace by itself, and first, because it forces a checkpoint;
# we'd prefer not to have checkpoints later in the tests because that
Expand Down
1 change: 1 addition & 0 deletions src/test/regress/serial_schedule
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# src/test/regress/serial_schedule
# This should probably be in an order similar to parallel_schedule.
test: local_distribution
test: tablespace
test: boolean
test: char
Expand Down
5 changes: 5 additions & 0 deletions src/test/regress/sql/local_distribution.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Creates db on coordinator shard without distributing

CREATE TABLE local_table (asd Int) DISTRIBUTED LOCAL;

EXPLAIN SELECT * FROM local_table;