Skip to content

Commit

Permalink
Merge pull request cockroachdb#55639 from nvanbenschoten/backport20.2…
Browse files Browse the repository at this point in the history
…-54064

release-20.2: workload/tpcc: properly partition order.order_idx index
  • Loading branch information
nvanbenschoten authored Oct 19, 2020
2 parents 973a6f3 + 91c0101 commit 03e5ced
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions pkg/workload/tpcc/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"bytes"
gosql "database/sql"
"fmt"
"strings"

"github.com/cockroachdb/errors"
"golang.org/x/exp/rand"
Expand Down Expand Up @@ -313,15 +314,12 @@ func partitionTable(
func partitionIndex(
db *gosql.DB, cfg zoneConfig, p *partitioner, table, index, col string, idx int,
) error {
indexStr := fmt.Sprintf("%s@%s", table, index)
if exists, err := indexExists(db, table, index); err != nil {
return err
} else if !exists {
// If the index doesn't exist then there's nothing to do. This is the
// case for a few of the indexes that are only needed for foreign keys
// when foreign keys are disabled.
return nil
return errors.Errorf("could not find index %q", indexStr)
}
indexStr := fmt.Sprintf("%s@%s", table, index)
return partitionObject(db, cfg, p, "INDEX", indexStr, col, table, idx)
}

Expand All @@ -345,10 +343,7 @@ func partitionOrder(db *gosql.DB, cfg zoneConfig, wPart *partitioner) error {
}

func partitionOrderLine(db *gosql.DB, cfg zoneConfig, wPart *partitioner) error {
if err := partitionTable(db, cfg, wPart, "order_line", "ol_w_id", 0); err != nil {
return err
}
return partitionIndex(db, cfg, wPart, "order_line", "order_line_stock_fk_idx", "ol_supply_w_id", 1)
return partitionTable(db, cfg, wPart, "order_line", "ol_w_id", 0)
}

func partitionStock(db *gosql.DB, cfg zoneConfig, wPart *partitioner) error {
Expand All @@ -366,13 +361,7 @@ func partitionCustomer(db *gosql.DB, cfg zoneConfig, wPart *partitioner) error {
}

func partitionHistory(db *gosql.DB, cfg zoneConfig, wPart *partitioner) error {
if err := partitionTable(db, cfg, wPart, "history", "h_w_id", 0); err != nil {
return err
}
if err := partitionIndex(db, cfg, wPart, "history", "history_customer_fk_idx", "h_c_w_id", 1); err != nil {
return err
}
return partitionIndex(db, cfg, wPart, "history", "history_district_fk_idx", "h_w_id", 2)
return partitionTable(db, cfg, wPart, "history", "h_w_id", 0)
}

// replicateItem creates a covering "replicated index" for the item table for
Expand Down Expand Up @@ -458,6 +447,9 @@ func partitionCount(db *gosql.DB) (int, error) {
}

func indexExists(db *gosql.DB, table, index string) (bool, error) {
// Strip any quotes around the table name.
table = strings.ReplaceAll(table, `"`, ``)

var exists bool
if err := db.QueryRow(`
SELECT count(*) > 0
Expand Down

0 comments on commit 03e5ced

Please sign in to comment.