Unwanted rows modified when using UPDATE on partitioned table : CTID are not unique in partitioned tables
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with src/storage/postgres_update.cpp at lines 49-70, then run the supplied PostgreSQL partitioned-table reproduction against DuckDB 1.2.1. Trace how CTID values are used to target rows during UPDATE. Done means updating category A changes only the two category A rows, including when the table has multiple partitions.
Written by the indexing model from the issue text.
Description
What happens?
When Duckdb updates a Postgres partitioned table, it will also update rows that are not wanted.
After a bit of digging, i found that currently, ctid are used by Duckdb to target the rows to update.
For standard table it works perfectly but not for partionned tables. Unfortunately, ctid are not unique for partitioned table. Instead, ctid are unique for each table that compose the partitioned table.
Here is my uneducated guess : This issue could be solved if the partionned keys are added to the final update statement.
It might be a bit tricky with multi level partition but doable.
To Reproduce
The postgresql partitioned table :
CREATE SCHEMA IF NOT EXISTS ctid_duplicate;
CREATE TABLE IF NOT EXISTS ctid_duplicate.my_table (
id integer,
category text,
data text,
PRIMARY KEY (id, category)
) PARTITION BY LIST (category);
CREATE TABLE IF NOT EXISTS ctid_duplicate.my_table_category_a
PARTITION OF ctid_duplicate.my_table
FOR VALUES IN ('A');
CREATE TABLE IF NOT EXISTS ctid_duplicate.my_table_category_b
PARTITION OF ctid_duplicate.my_table
FOR VALUES IN ('B');
CREATE TABLE IF NOT EXISTS ctid_duplicate.my_table_category_c
PARTITION OF ctid_duplicate.my_table
FOR VALUES IN ('C');
INSERT INTO ctid_duplicate.my_table (id, category, data)
VALUES
(1, 'A', 'Data for category A'),
(2, 'B', 'Data for category B'),
(3, 'C', 'Data for category C'),
(4, 'A', 'Another data for category A');
A simple simple select let us see that ctid aren't unique
SELECT ctid, id, category, "data"
FROM ctid_duplicate.my_table;
Now to actually test the issue with DuckDB :
ATTACH if not exists 'postgresql://sco:sco@localhost:5432/rece' as postgres_rece (type POSTGRES);
update postgres_rece.ctid_duplicate.my_table
set data = 'CTID are duplicated'
where category = 'A';
Let's check again the table, only 2 rows should have been updated :
select * from postgres_rece.ctid_duplicate.my_table;
The results :
OS:
ubuntu 22.04
PostgreSQL Version:
15.8
DuckDB Version:
1.2.1
DuckDB Client:
Python
Full Name:
Simon Cotte
Affiliation:
AtolCD
Have you tried this on the latest main branch?
- I agree
Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?
- I agree
- Dominant language
- C++
- Stars
- 373
- Forks
- 112
- Avg merge
- 9h 48m
- Merged PRs (30d)
- 28
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from duckdb/duckdb-postgres
-
Difficulty 3/5 1-2 days Newbie friendliness 62/100
duckdb/duckdb-postgres#618 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
duckdb/duckdb-postgres#594 · 4 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
duckdb/duckdb-postgres#575 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 74/100
duckdb/duckdb-postgres#564 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
duckdb/duckdb-postgres#491 · 1 comment ·
Maintainers usually reply within 1 day
All issues in duckdb/duckdb-postgres
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
[BUG] Clipboard History: Buffer over-read in WideCharToMultiByte on double-click pastePossibly taken @softmgr claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
notepad-plus-plus/notepad-plus-plus#18519 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
justcallmekoko/ESP32Marauder#1635 ·
Maintainers usually reply within 1 day
-
3.7.6-dev commit 80481ea - files not centered when resolution differs and zoom = "pixel-to-pixel"Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
grizzlypeak3d/DJV#931 ·