Skip to content

Commit

Permalink
Merge branch 'users/paragjain/mergeWriteFix' of https://github.com/pa…
Browse files Browse the repository at this point in the history
…ragikjain/citus into users/paragjain/mergeWriteFix
  • Loading branch information
paragikjain committed Sep 13, 2024
2 parents 1a3c676 + 5fae4d4 commit 5318c40
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/.psqlrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
\pset border 2
\setenv PAGER 'pspg --no-mouse -bX --no-commandbar --no-topbar'
\set HISTSIZE 100000
\set PROMPT1 '\n%[%033[1m%]%M %n@%/:%>-%p%R%[%033[0m%]%# '
\set PROMPT1 '\n%[%033[1m%]%M %n@%/:%> (PID: %p)%R%[%033[0m%]%# '
\set PROMPT2 ' '
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### citus v12.1.5 (July 17, 2024) ###

* Adds support for MERGE commands with single shard distributed target tables
(#7643)

* Fixes an error with MERGE commands when insert value does not have source
distribution column (#7627)

### citus v12.1.4 (May 28, 2024) ###

* Adds null check for node in HasRangeTableRef (#7604)
Expand Down
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ To get citus installed from source we run `make install -s` in the first termina

With the Citus cluster running you can connect to the coordinator in the first terminal via `psql -p9700`. Because the coordinator is the most common entrypoint the `PGPORT` environment is set accordingly, so a simple `psql` will connect directly to the coordinator.

### Debugging in the VS code

1. Start Debugging: Press F5 in VS Code to start debugging. When prompted, you'll need to attach the debugger to the appropriate PostgreSQL process.

2. Identify the Process: If you're running a psql command, take note of the PID that appears in your psql prompt. For example:
```
[local] citus@citus:9700 (PID: 5436)=#
```
This PID (5436 in this case) indicates the process that you should attach the debugger to.
If you are uncertain about which process to attach, you can list all running PostgreSQL processes using the following command:
```
ps aux | grep postgres
```

Look for the process associated with the PID you noted. For example:
```
citus 5436 0.0 0.0 0 0 ? S 14:00 0:00 postgres: citus citus
```
4. Attach the Debugger: Once you've identified the correct PID, select that process when prompted in VS Code to attach the debugger. You should now be able to debug the PostgreSQL session tied to the psql command.

5. Set Breakpoints and Debug: With the debugger attached, you can set breakpoints within the code. This allows you to step through the code execution, inspect variables, and fully debug the PostgreSQL instance running in your container.

### Getting and building

[PostgreSQL documentation](https://www.postgresql.org/support/versioning/) has a
Expand Down
1 change: 1 addition & 0 deletions citus-tools
Submodule citus-tools added at 3376bd
3 changes: 3 additions & 0 deletions src/backend/distributed/metadata/node_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ citus_set_coordinator_host(PG_FUNCTION_ARGS)
EnsureTransactionalMetadataSyncMode();
}

/* prevent concurrent modification */
LockRelationOid(DistNodeRelationId(), RowExclusiveLock);

bool isCoordinatorInMetadata = false;
WorkerNode *coordinatorNode = PrimaryNodeForGroup(COORDINATOR_GROUP_ID,
&isCoordinatorInMetadata);
Expand Down
29 changes: 21 additions & 8 deletions src/backend/distributed/planner/multi_logical_optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4753,22 +4753,35 @@ WorkerLimitCount(Node *limitCount, Node *limitOffset, OrderByLimitReference
if (workerLimitNode != NULL && limitOffset != NULL)
{
Const *workerLimitConst = (Const *) workerLimitNode;
Const *workerOffsetConst = (Const *) limitOffset;
int64 workerLimitCount = DatumGetInt64(workerLimitConst->constvalue);
int64 workerOffsetCount = DatumGetInt64(workerOffsetConst->constvalue);

workerLimitCount = workerLimitCount + workerOffsetCount;
workerLimitNode = (Node *) MakeIntegerConstInt64(workerLimitCount);
/* Only update the worker limit if the const is not null.*/
if (!workerLimitConst->constisnull)
{
Const *workerOffsetConst = (Const *) limitOffset;
int64 workerLimitCount = DatumGetInt64(workerLimitConst->constvalue);

/* If the offset is null, it defaults to 0 when cast to int64. */
int64 workerOffsetCount = DatumGetInt64(workerOffsetConst->constvalue);
workerLimitCount = workerLimitCount + workerOffsetCount;
workerLimitNode = (Node *) MakeIntegerConstInt64(workerLimitCount);
}
}

/* display debug message on limit push down */
if (workerLimitNode != NULL)
{
Const *workerLimitConst = (Const *) workerLimitNode;
int64 workerLimitCount = DatumGetInt64(workerLimitConst->constvalue);
if (!workerLimitConst->constisnull)
{
int64 workerLimitCount = DatumGetInt64(workerLimitConst->constvalue);

ereport(DEBUG1, (errmsg("push down of limit count: " INT64_FORMAT,
workerLimitCount)));
ereport(DEBUG1, (errmsg("push down of limit count: " INT64_FORMAT,
workerLimitCount)));
}
else
{
ereport(DEBUG1, (errmsg("push down of limit count: ALL")));
}
}

return workerLimitNode;
Expand Down
80 changes: 80 additions & 0 deletions src/test/regress/expected/multi_limit_clause.out
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,86 @@ SELECT
1 | 1
(1 row)

-- check if we can correctly push the limit when it is null
SELECT l_orderkey FROM lineitem WHERE l_orderkey < 3 ORDER BY l_orderkey LIMIT null;
DEBUG: push down of limit count: ALL
l_orderkey
---------------------------------------------------------------------
1
1
1
1
1
1
2
(7 rows)

SELECT l_orderkey FROM lineitem WHERE l_orderkey < 3 ORDER BY l_orderkey OFFSET 1 LIMIT null;
DEBUG: push down of limit count: ALL
l_orderkey
---------------------------------------------------------------------
1
1
1
1
1
2
(6 rows)

SELECT count(*) FROM lineitem LIMIT null;
DEBUG: push down of limit count: ALL
count
---------------------------------------------------------------------
12000
(1 row)

SELECT count(*) FROM lineitem OFFSET 0 LIMIT null;
DEBUG: push down of limit count: ALL
count
---------------------------------------------------------------------
12000
(1 row)

-- check if we push the right limit when both offset and limit are given
SELECT l_orderkey FROM lineitem WHERE l_orderkey < 3 ORDER BY l_orderkey OFFSET 1 LIMIT 3;
DEBUG: push down of limit count: 4
l_orderkey
---------------------------------------------------------------------
1
1
1
(3 rows)

SELECT l_orderkey FROM lineitem WHERE l_orderkey < 3 ORDER BY l_orderkey OFFSET null LIMIT 1;
DEBUG: push down of limit count: 1
l_orderkey
---------------------------------------------------------------------
1
(1 row)

-- check if we can correctly push the limit when it is all
SELECT l_orderkey FROM lineitem WHERE l_orderkey < 2 LIMIT all;
DEBUG: push down of limit count: ALL
l_orderkey
---------------------------------------------------------------------
1
1
1
1
1
1
(6 rows)

SELECT l_orderkey FROM lineitem WHERE l_orderkey < 2 OFFSET 2 LIMIT all;
DEBUG: push down of limit count: ALL
l_orderkey
---------------------------------------------------------------------
1
1
1
1
(4 rows)

SET client_min_messages TO NOTICE;
-- non constants should not push down
CREATE OR REPLACE FUNCTION my_limit()
Expand Down
19 changes: 19 additions & 0 deletions src/test/regress/sql/multi_limit_clause.sql
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,25 @@ SELECT
ORDER BY 2 DESC, 1
LIMIT 5;

-- check if we can correctly push the limit when it is null
SELECT l_orderkey FROM lineitem WHERE l_orderkey < 3 ORDER BY l_orderkey LIMIT null;

SELECT l_orderkey FROM lineitem WHERE l_orderkey < 3 ORDER BY l_orderkey OFFSET 1 LIMIT null;

SELECT count(*) FROM lineitem LIMIT null;

SELECT count(*) FROM lineitem OFFSET 0 LIMIT null;

-- check if we push the right limit when both offset and limit are given
SELECT l_orderkey FROM lineitem WHERE l_orderkey < 3 ORDER BY l_orderkey OFFSET 1 LIMIT 3;

SELECT l_orderkey FROM lineitem WHERE l_orderkey < 3 ORDER BY l_orderkey OFFSET null LIMIT 1;

-- check if we can correctly push the limit when it is all
SELECT l_orderkey FROM lineitem WHERE l_orderkey < 2 LIMIT all;

SELECT l_orderkey FROM lineitem WHERE l_orderkey < 2 OFFSET 2 LIMIT all;

SET client_min_messages TO NOTICE;

-- non constants should not push down
Expand Down

0 comments on commit 5318c40

Please sign in to comment.