---
# System prepended metadata

title: isucon9 final

---

# isucon9 final


main.goで使われているsql
```txt
stdin.go:291:24 in getUser
	SELECT * FROM `users` WHERE `id` = ?

stdin.go:315:11 in distanceFareHandler
	SELECT * FROM distance_fare_master

stdin.go:334:11 in getDistanceFare
	SELECT distance,fare FROM distance_fare_master ORDER BY distance

stdin.go:364:11 in fareCalc
	SELECT * FROM station_master WHERE id=?

stdin.go:404:10 in fareCalc
	SELECT * FROM fare_master WHERE train_class=? AND seat_class=? ORDER BY start_date

stdin.go:438:11 in getStationsHandler
	SELECT * FROM station_master ORDER BY id

stdin.go:482:11 in trainSearchHandler
	SELECT * FROM station_master WHERE name=?

stdin.go:514:10 in trainSearchHandler
	SELECT * FROM station_master ORDER BY distance

stdin.go:526:12 in trainSearchHandler
	SELECT * FROM train_master WHERE date=? AND train_class IN (?) AND is_nobori=?

stdin.go:529:12 in trainSearchHandler
	SELECT * FROM train_master WHERE date=? AND train_class IN (?) AND is_nobori=? AND train_class=?

stdin.go:602:30 in trainSearchHandler
	SELECT departure FROM train_timetable_master WHERE date=? AND train_class=? AND train_name=? AND station=?

stdin.go:619:28 in trainSearchHandler
	SELECT arrival FROM train_timetable_master WHERE date=? AND train_class=? AND train_name=? AND station=?

stdin.go:760:11 in trainSeatsHandler
	SELECT * FROM train_master WHERE date=? AND train_class=? AND train_name=?

stdin.go:771:10 in trainSeatsHandler
	SELECT * FROM station_master WHERE name=?

stdin.go:816:10 in trainSeatsHandler
	SELECT * FROM seat_master WHERE train_class=? AND car_number=? ORDER BY seat_row, seat_column

stdin.go:832:12 in trainSeatsHandler

SELECT s.*
FROM seat_reservations s, reservations r
WHERE
	r.date=? AND r.train_class=? AND r.train_name=? AND car_number=? AND seat_row=? AND seat_column=?


stdin.go:868:12 in trainSeatsHandler
	SELECT * FROM reservations WHERE reservation_id=?

stdin.go:875:12 in trainSeatsHandler
	SELECT * FROM station_master WHERE name=?

stdin.go:918:10 in trainSeatsHandler
	SELECT * FROM seat_master WHERE train_class=? AND car_number=? ORDER BY seat_row, seat_column LIMIT 1

stdin.go:996:11 in trainReservationHandler
	SELECT * FROM train_master WHERE date=? AND train_class=? AND train_name=?

stdin.go:1018:10 in trainReservationHandler
	SELECT * FROM station_master WHERE name=?

stdin.go:1051:10 in trainReservationHandler
	SELECT * FROM station_master WHERE name=?

stdin.go:1145:12 in trainReservationHandler
	SELECT * FROM train_master WHERE date=? AND train_class=? AND train_name=?

stdin.go:1174:12 in trainReservationHandler
	SELECT * FROM seat_master WHERE train_class=? AND car_number=? AND seat_class=? AND is_smoking_seat=? ORDER BY seat_row, seat_column

stdin.go:1186:13 in trainReservationHandler
	SELECT s.* FROM seat_reservations s, reservations r WHERE r.date=? AND r.train_class=? AND r.train_name=? AND car_number=? AND seat_row=? AND seat_column=? FOR UPDATE

stdin.go:1204:14 in trainReservationHandler
	SELECT * FROM reservations WHERE reservation_id=? FOR UPDATE

stdin.go:1211:14 in trainReservationHandler
	SELECT * FROM station_master WHERE name=?

stdin.go:1317:12 in trainReservationHandler
	SELECT * FROM seat_master WHERE train_class=? AND car_number=? AND seat_column=? AND seat_row=? AND seat_class=?

stdin.go:1338:10 in trainReservationHandler
	SELECT * FROM reservations WHERE date=? AND train_class=? AND train_name=? FOR UPDATE

stdin.go:1358:11 in trainReservationHandler
	SELECT * FROM train_master WHERE date=? AND train_class=? AND train_name=?

stdin.go:1380:11 in trainReservationHandler
	SELECT * FROM station_master WHERE name=?

stdin.go:1438:13 in trainReservationHandler
	SELECT * FROM seat_reservations WHERE reservation_id=? FOR UPDATE

stdin.go:1521:10 in trainReservationHandler
	INSERT INTO `reservations` (`user_id`, `date`, `train_class`, `train_name`, `departure`, `arrival`, `status`, `payment_id`, `adult`, `child`, `amount`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

stdin.go:1553:10 in trainReservationHandler
	INSERT INTO `seat_reservations` (`reservation_id`, `car_number`, `seat_row`, `seat_column`) VALUES (?, ?, ?, ?)

stdin.go:1612:11 in reservationPaymentHandler
	SELECT * FROM reservations WHERE reservation_id=?

stdin.go:1704:10 in reservationPaymentHandler
	UPDATE reservations SET status=?, payment_id=? WHERE reservation_id=?

stdin.go:1770:3 in signUpHandler
	INSERT INTO `users` (`email`, `salt`, `super_secure_password`) VALUES (?, ?, ?)

stdin.go:1796:11 in loginHandler
	SELECT * FROM users WHERE email=?

stdin.go:1849:3 in makeReservationResponse
	SELECT departure FROM train_timetable_master WHERE date=? AND train_class=? AND train_name=? AND station=?

stdin.go:1857:3 in makeReservationResponse
	SELECT arrival FROM train_timetable_master WHERE date=? AND train_class=? AND train_name=? AND station=?

stdin.go:1876:11 in makeReservationResponse
	SELECT * FROM seat_reservations WHERE reservation_id=?

stdin.go:1933:11 in userReservationsHandler
	SELECT * FROM reservations WHERE user_id=?

stdin.go:1974:11 in userReservationResponseHandler
	SELECT * FROM reservations WHERE reservation_id=? AND user_id=?

stdin.go:2013:11 in userReservationCancelHandler
	SELECT * FROM reservations WHERE reservation_id=? AND user_id=?

stdin.go:2048:31 in userReservationCancelHandler
	DELETE

stdin.go:2093:10 in userReservationCancelHandler
	DELETE FROM reservations WHERE reservation_id=? AND user_id=?

stdin.go:2101:10 in userReservationCancelHandler
	DELETE FROM seat_reservations WHERE reservation_id=?

stdin.go:2130:11 in initializeHandler
	SELECT * FROM station_master ORDER BY id

stdin.go:2142:10 in initializeHandler
	SELECT * FROM seat_master
```


utils.goで使われているsql

```txt
stdin.go:57:11 in getAvailableSeats
	SELECT * FROM seat_master WHERE train_class=? AND seat_class=? AND is_smoking_seat=?

stdin.go:71:10 in getAvailableSeats

	SELECT sr.reservation_id, sr.car_number, sr.seat_row, sr.seat_column
	FROM seat_reservations sr, reservations r, seat_master s, station_master std, station_master sta
	WHERE
		r.reservation_id=sr.reservation_id AND
		s.train_class=r.train_class AND
		s.car_number=sr.car_number AND
		s.seat_column=sr.seat_column AND
		s.seat_row=sr.seat_row AND
		std.name=r.departure AND
		sta.name=r.arrival
```