Skip to content
Permalink
Browse files

Use UNION instead of OR

  • Loading branch information...
takonomura committed Sep 8, 2019
1 parent 1cd1a0e commit 6d68a384bb1aa67e746dfb0350402e8dfaa743e5
Showing with 3 additions and 7 deletions.
  1. +1 −6 isucari/webapp/go/main.go
  2. +2 −1 isucari/webapp/sql/01_schema.sql
@@ -925,14 +925,9 @@ func getTransactions(w http.ResponseWriter, r *http.Request) {
} else {
// 1st page
err := tx.SelectContext(r.Context(), &items,
"SELECT * FROM `items` WHERE (`seller_id` = ? OR `buyer_id` = ?) AND `status` IN (?,?,?,?,?) ORDER BY `created_at` DESC, `id` DESC LIMIT ?",
"SELECT * FROM (SELECT * FROM `items` WHERE `seller_id` = ? AND `status` IN ('on_sale','trading','sold_out','cancel','stop') UNION SELECT * FROM `items` WHERE `buyer_id` = ? AND `status` IN ('on_sale','trading','sold_out','cancel','stop')) t ORDER BY `created_at` DESC, `id` DESC LIMIT ?",
user.ID,
user.ID,
ItemStatusOnSale,
ItemStatusTrading,
ItemStatusSoldOut,
ItemStatusCancel,
ItemStatusStop,
TransactionsPerPage+1,
)
if err != nil {
@@ -33,7 +33,8 @@ CREATE TABLE `items` (
INDEX idx_category_id (`category_id`),
INDEX idx_created_at (`created_at`),
INDEX idx_seller_id_created_at (seller_id, created_at),
INDEX idx_category_id_created_at (category_id, created_at)
INDEX idx_category_id_created_at (category_id, created_at),
INDEX idx_buyer_id_created_at (buyer_id, created_at)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4;

DROP TABLE IF EXISTS `transaction_evidences`;

0 comments on commit 6d68a38

Please sign in to comment.
You can’t perform that action at this time.