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

TT-13421 create indexes on sharded sql pumps #861

Merged
merged 20 commits into from
Dec 5, 2024

Conversation

sredxny
Copy link
Contributor

@sredxny sredxny commented Nov 21, 2024

Description

Related Issue

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side). If pulling from your own
    fork, don't request your master!
  • Make sure you are making a pull request against the master branch (left side). Also, you should start
    your branch off our latest master.
  • My change requires a change to the documentation.
    • If you've changed APIs, describe what needs to be updated in the documentation.
  • I have updated the documentation accordingly.
  • Modules and vendor dependencies have been updated; run go mod tidy && go mod vendor
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • Check your code additions will not fail linting checks:
    • go fmt -s
    • go vet

pumps/sql.go Outdated Show resolved Hide resolved
pumps/sql.go Outdated Show resolved Hide resolved
pumps/sql.go Outdated Show resolved Hide resolved
pumps/sql.go Outdated Show resolved Hide resolved
pumps/sql.go Show resolved Hide resolved
@jeffy-mathew
Copy link

@sredxny since we're using gorm, shall we explore the possibility of using NamingStrategy in gorm config?

@sredxny sredxny requested a review from jeffy-mathew November 28, 2024 21:20
@sredxny sredxny enabled auto-merge (squash) December 1, 2024 15:04
@sredxny sredxny requested a review from mativm02 December 4, 2024 20:27
pumps/sql.go Outdated
return errors.New("cannot create index for non existent column " + column)
}

sql := fmt.Sprintf("CREATE INDEX %s IF NOT EXISTS %s ON %s (%s)", option, indexName, tableName, column)
Copy link
Contributor

Choose a reason for hiding this comment

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

A better naming for this variable could be query, what do you think?

Choose a reason for hiding this comment

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

In addition to this, let's bring in practise to be careful when forming SQL queries. I know the values in this query are totally under our control (consts), but still I feel like it's better to use an sql builder. https://gorm.io/docs/sql_builder.html - this might help

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed.... @jeffy-mathew in such case we would need to add some logic like:

query := "CREATE INDEX IF NOT EXISTS ? ON ? (?)"
if option != "" {
    query = fmt.Sprintf("CREATE INDEX %s IF NOT EXISTS ? ON ? (?)", option) // Add option dynamically
}

As the original query contains a param "option" that can be "concunrrently" or empty, and db.Raw method doesnt allows it and will mark it as bad query

pumps/sql_aggregate.go Outdated Show resolved Hide resolved
@sredxny sredxny requested a review from mativm02 December 5, 2024 16:03
@sredxny sredxny merged commit 544ccb3 into master Dec 5, 2024
31 checks passed
@sredxny sredxny deleted the TT-13421-create-indexes-on-sharded-sql-pumps branch December 5, 2024 19:03
@sredxny
Copy link
Contributor Author

sredxny commented Dec 5, 2024

/release to release-1.11

Copy link

tykbot bot commented Dec 5, 2024

Working on it! Note that it can take a few minutes.

tykbot bot pushed a commit that referenced this pull request Dec 5, 2024
* started to add indexes to shards

* create indexes when SQL pump is sharded

* added test for ensure index in SQL pump

* update sql aggregate to handle multiple indexes on sharded analytics

* update SQL aggregate test

* isolate index build logic

* some refactor

* fixing test for indexes in SQL pump

* gofmt sql_test.go

* check drop table err

* gofumpt

* ensuring table for SQL

* gofumpt

* refactoring ensureIndex in sql pump

* improve logging

* refactor logic while looping over indexes

* gofumpt

* only use the waitgroup for background

---------

Co-authored-by: sredny buitrago <[email protected]>

(cherry picked from commit 544ccb3)
Copy link

tykbot bot commented Dec 5, 2024

@sredxny Seems like there is conflict and it require manual merge.

mativm02 pushed a commit that referenced this pull request Dec 11, 2024
* started to add indexes to shards

* create indexes when SQL pump is sharded

* added test for ensure index in SQL pump

* update sql aggregate to handle multiple indexes on sharded analytics

* update SQL aggregate test

* isolate index build logic

* some refactor

* fixing test for indexes in SQL pump

* gofmt sql_test.go

* check drop table err

* gofumpt

* ensuring table for SQL

* gofumpt

* refactoring ensureIndex in sql pump

* improve logging

* refactor logic while looping over indexes

* gofumpt

* only use the waitgroup for background

---------

Co-authored-by: sredny buitrago <[email protected]>

(cherry picked from commit 544ccb3)

Co-authored-by: Sredny M. <[email protected]>
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.

3 participants