Skip to content

Commit

Permalink
SQL - replaced "values" and string concat with array and unnest
Browse files Browse the repository at this point in the history
  • Loading branch information
tzahij committed Nov 2, 2020
1 parent eb716ee commit 40f916b
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions catalog/cataloger_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"strings"

sq "github.com/Masterminds/squirrel"
"github.com/treeverse/lakefs/db"
Expand Down Expand Up @@ -209,10 +208,9 @@ func applyDiffChangesToRightBranch(tx db.Tx, mergeBatch mergeBatchRecords, previ
}
// insert tombstones into parent branch that has a removed entry in its lineage
if len(tombstonePaths) > 0 {
values := "(VALUES ('" + strings.Join(tombstonePaths, "'),('") + "')) AS t(path)"
sql := `INSERT INTO catalog_entries (branch_id,path,physical_address,size,checksum,metadata,min_commit,max_commit)
SELECT $1,path,'',0,'','{}',$2,0 FROM ` + values
_, err := tx.Exec(sql, rightID, previousMaxCommitID)
SELECT $1,path,'',0,'','{}',$2,0 FROM(SELECT * FROM UNNEST($3::text []))t(path)`
_, err := tx.Exec(sql, rightID, previousMaxCommitID, tombstonePaths)
if err != nil {
return err
}
Expand Down

0 comments on commit 40f916b

Please sign in to comment.