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

Use left joins in subset queries for nullable foreign keys #3034

Merged
merged 6 commits into from
Dec 11, 2024

Conversation

alishakawaguchi
Copy link
Contributor

No description provided.

@alishakawaguchi alishakawaguchi added the Improvement Created by Linear-GitHub Sync label Dec 11, 2024
@alishakawaguchi alishakawaguchi self-assigned this Dec 11, 2024
Copy link

linear bot commented Dec 11, 2024

Copy link

vercel bot commented Dec 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
neosync-docs ⬜️ Ignored (Inspect) Visit Preview Dec 11, 2024 9:54pm

Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 29 lines in your changes missing coverage. Please review.

Project coverage is 34.71%. Comparing base (25f61d9) to head (2549092).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
internal/benthos/benthos-builder/builders/sql.go 5.88% 16 Missing ⚠️
worker/pkg/query-builder2/querybuilder.go 78.94% 10 Missing and 2 partials ⚠️
worker/pkg/query-builder2/wrapper.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3034      +/-   ##
==========================================
- Coverage   34.80%   34.71%   -0.10%     
==========================================
  Files         345      345              
  Lines       39713    40113     +400     
==========================================
+ Hits        13824    13926     +102     
- Misses      24273    24564     +291     
- Partials     1616     1623       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -322,6 +334,12 @@ func (b *sqlSyncBuilder) BuildDestinationConfig(ctx context.Context, params *bb_
return nil, fmt.Errorf("unable to parse destination options: %w", err)
}

// skip foreign key violations if the query could return rows that violate foreign key constraints
skipForeignKeyViolations := destOpts.SkipForeignKeyViolations
Copy link
Member

Choose a reason for hiding this comment

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

I think this can actually be more concisely written as well as short circuited:

skipForeignKeyViolations := destOpts.SkipForeignKeyViolations || b.isNotForeignKeySafeSubsetMap[tableKey]

@@ -148,6 +152,14 @@ func (b *sqlSyncBuilder) BuildSourceConfigs(ctx context.Context, params *bb_inte
return nil, fmt.Errorf("unable to build select queries: %w", err)
}

for table, querymap := range tableRunTypeQueryMap {
for runtype, q := range querymap {
if runtype == tabledependency.RunTypeInsert {
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this slightly inaccurate? Won't it only be not FK subset safe if it contains nullable FKs?
Maybe just my context here is too limited.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure I understand. this map is tracking whether a tables query is fk subset safe. the t/f value comes from the querybuilder

Copy link
Member

Choose a reason for hiding this comment

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

so in this case youre only using the value if it is an insert, is that what's going on here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I mean I could separate it by runtype but the isNotForeignKeySafeSubsetMap value is the same for insert or update. I could remove the runtype check and just have it overwrite the value since the insert and update are the same

Copy link
Member

Choose a reason for hiding this comment

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

Idk, maybe just a nice comment would suffice

@alishakawaguchi alishakawaguchi merged commit f3d58a8 into main Dec 11, 2024
9 of 10 checks passed
@alishakawaguchi alishakawaguchi deleted the alisha/neos-1667-left-joins branch December 11, 2024 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement Created by Linear-GitHub Sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants