Permalink
Browse files

Optimize indices for large tables

Adding an index on instance_id and created_at will allow
the dataset to be ordered and filtered a lot faster, especially
when there are a lot of orders.
Also, since the custom names for indices are removed, indices will
now be properly prefixed.
  • Loading branch information...
mraerino committed Jan 29, 2019
1 parent d717211 commit e713513cf3388624918f1f1c178d5bad3098a96f
Showing with 4 additions and 4 deletions.
  1. +1 −1 models/download.go
  2. +3 −3 models/order.go
@@ -22,7 +22,7 @@ type Download struct {

CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `json:"-" sql:"index:idx_downloads_deleted_at"`
DeletedAt *time.Time `json:"-" sql:"index"`
}

// TableName returns the database table name for the Download model.
@@ -50,7 +50,7 @@ const (

// Order model
type Order struct {
InstanceID string `json:"-"`
InstanceID string `json:"-" sql:"index"`
ID string `json:"id"`
InvoiceNumber int64 `json:"invoice_number,omitempty"`

@@ -100,9 +100,9 @@ type Order struct {
Coupon *Coupon `json:"coupon,omitempty" sql:"-"`
RawCoupon string `json:"-" sql:"type:text"`

CreatedAt time.Time `json:"created_at"`
CreatedAt time.Time `json:"created_at" sql:"index"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `json:"-" sql:"index:idx_orders_deleted_at"`
DeletedAt *time.Time `json:"-" sql:"index"`
}

// TableName returns the database table name for the Order model.

0 comments on commit e713513

Please sign in to comment.