Skip to content

Fixed primary key metadata. - #3118

Merged
khustup2 merged 2 commits into
mainfrom
fix-pk
Jan 20, 2026
Merged

Fixed primary key metadata.#3118
khustup2 merged 2 commits into
mainfrom
fix-pk

Conversation

@khustup2

Copy link
Copy Markdown
Contributor

🚀 🚀 Pull Request

Impact

  • Bug fix (non-breaking change which fixes expected existing functionality)
  • Enhancement/New feature (adds functionality without impacting existing logic)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

Things to be aware of

Things to worry about

Additional Context

Copilot AI review requested due to automatic review settings January 20, 2026 01:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request removes the workaround that ignored primary key constraints and restores proper primary key enforcement. The change addresses the transition from bypassing primary key constraints to allowing PostgreSQL's native constraint system to handle them correctly.

Changes:

  • Removed the ignore_primary_keys configuration parameter and related constraint-stripping logic
  • Cleaned up primary key metadata tracking code that was part of the workaround
  • Updated tests to reflect proper primary key constraint enforcement expectations

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
postgres/tests/py_tests/test_update_table.py Corrected expected query results after fixing vector distance calculations
postgres/tests/py_tests/test_random_operations.py Added comprehensive test suite for random data operations and schema evolution
postgres/tests/py_tests/test_constraint_enforcement.py Added tests documenting current constraint enforcement bugs
cpp/deeplake_pg/utils.hpp Removed ignore_primary_keys global variable declaration
cpp/deeplake_pg/table_storage.hpp Removed primary key metadata storage and related methods
cpp/deeplake_pg/table_storage.cpp Removed primary key setting logic during table creation
cpp/deeplake_pg/table_data_impl.hpp Removed primary key indexing implementation
cpp/deeplake_pg/table_data.hpp Removed primary key setter method declaration
cpp/deeplake_pg/extension_init.cpp Removed GUC parameter and primary key constraint stripping logic

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


expected_ids_after = [1, 2, 3, 4]
# After update: id=2 has [9,10,11] which is farther from query [1,2,3] than id=3's [7,8,9]
# L2 distances: id=1=0, id=3=10.4, id=2=13.9, id=4=441

Copilot AI Jan 20, 2026

Copy link

Choose a reason for hiding this comment

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

The L2 distance calculation for id=3 appears incorrect. For vectors [7,8,9] and [1,2,3], the L2 distance should be sqrt((7-1)² + (8-2)² + (9-3)²) = sqrt(36 + 36 + 36) = sqrt(108) ≈ 10.39. The comment shows '10.4' which is approximately correct but should be more precise or show the calculation. Similarly, verify the distance for id=2.

Suggested change
# L2 distances: id=1=0, id=3=10.4, id=2=13.9, id=4=441
# L2 distances from [1,2,3]:
# id=1: sqrt((1-1)^2 + (2-2)^2 + (3-3)^2) = sqrt(0) = 0
# id=3: sqrt((7-1)^2 + (8-2)^2 + (9-3)^2) = sqrt(108) ≈ 10.39
# id=2: sqrt((9-1)^2 + (10-2)^2 + (11-3)^2) = sqrt(192) ≈ 13.86
# id=4: sqrt((0-1)^2 + (0-2)^2 + (444-3)^2) = sqrt(194486)≈ 441.04

Copilot uses AI. Check for mistakes.
Comment on lines +542 to +551
# Test integer equality
random_int = random.randint(0, 100)
count = await db_conn.fetchval(f"""
SELECT count(*) FROM filter_test WHERE int_val = {random_int}
""")
# Should have some matches (roughly 1% of rows)
assert count >= 0, f"Count should be non-negative for int_val = {random_int}"

# Test range queries
low, high = sorted([random.randint(0, 100), random.randint(0, 100)])

Copilot AI Jan 20, 2026

Copy link

Choose a reason for hiding this comment

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

This assertion is trivial as COUNT(*) can never be negative. If the intent is to verify the query executes without error, consider adding a meaningful check or removing this assertion.

Suggested change
# Test integer equality
random_int = random.randint(0, 100)
count = await db_conn.fetchval(f"""
SELECT count(*) FROM filter_test WHERE int_val = {random_int}
""")
# Should have some matches (roughly 1% of rows)
assert count >= 0, f"Count should be non-negative for int_val = {random_int}"
# Test range queries
low, high = sorted([random.randint(0, 100), random.randint(0, 100)])
# Test integer equality (ensure query executes correctly)
random_int = random.randint(0, 100)
count = await db_conn.fetchval(f"""
SELECT count(*) FROM filter_test WHERE int_val = {random_int}
""")
# Test range queries
low, high = sorted([random.randint(0, 100), random.randint(0, 100)])
low, high = sorted([random.randint(0, 100), random.randint(0, 100)])

Copilot uses AI. Check for mistakes.
Comment on lines +599 to +600
# Should be roughly: 50% * 50% * 75% = 18.75%
assert combined_count >= 0, "Combined filter should return non-negative count"

Copilot AI Jan 20, 2026

Copy link

Choose a reason for hiding this comment

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

This assertion is trivial as COUNT(*) can never be negative. Consider removing this assertion or adding a more meaningful validation.

Suggested change
# Should be roughly: 50% * 50% * 75% = 18.75%
assert combined_count >= 0, "Combined filter should return non-negative count"
# Should be roughly: 50% * 50% * 75% = 18.75% of num_rows
assert int(0.05 * num_rows) < combined_count < int(0.4 * num_rows), \
f"Combined filter count {combined_count} is outside expected range for {num_rows} rows"

Copilot uses AI. Check for mistakes.
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
39 Security Hotspots

See analysis details on SonarQube Cloud

@khustup2
khustup2 merged commit 82ad034 into main Jan 20, 2026
5 of 6 checks passed
@khustup2
khustup2 deleted the fix-pk branch January 20, 2026 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants