Skip to content

Instantly share code, notes, and snippets.

@Barbayar
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save Barbayar/fa56bb2669708c313a65 to your computer and use it in GitHub Desktop.

Select an option

Save Barbayar/fa56bb2669708c313a65 to your computer and use it in GitHub Desktop.
ISUCON 4

Query List

             'SELECT COUNT(1) AS failures FROM login_log WHERE ' +
                'user_id = ? AND id > IFNULL((select id from login_log where ' +
                'user_id = ? AND succeeded = 1 ORDER BY id DESC LIMIT 1), 0);',
            'SELECT COUNT(1) AS failures FROM login_log WHERE ' +
                'ip = ? AND id > IFNULL((select id from login_log where ip = ? AND ' +
                'succeeded = 1 ORDER BY id DESC LIMIT 1), 0);',
SELECT * FROM users WHERE login = ?
                'INSERT INTO login_log' +
                    ' (`created_at`, `user_id`, `login`, `ip`, `succeeded`)' +
                    ' VALUES (?,?,?,?,?)',
SELECT * FROM users WHERE id = ?
            'SELECT ip FROM (SELECT ip, MAX(succeeded) as max_succeeded, COUNT(1) as cnt FROM '+
                'login_log GROUP BY ip) AS t0 WHERE t0.max_succeeded = 0 AND t0.cnt >= ?',
SELECT ip, MAX(id) AS last_login_id FROM login_log WHERE succeeded = 1 GROUP by ip
SELECT COUNT(1) AS cnt FROM login_log WHERE ip = ? AND ? < id
            'SELECT user_id, login FROM ' +
                '(SELECT user_id, login, MAX(succeeded) as max_succeeded, COUNT(1) as cnt FROM ' +
                'login_log GROUP BY user_id) AS t0 WHERE t0.user_id IS NOT NULL AND ' +
                't0.max_succeeded = 0 AND t0.cnt >= ?',
                    'SELECT user_id, login, MAX(id) AS last_login_id FROM login_log WHERE ' +
                        'user_id IS NOT NULL AND succeeded = 1 GROUP BY user_id',
                                        'SELECT COUNT(1) AS cnt FROM login_log WHERE user_id = ? AND ? < id',
                                        [row['user_id'], row['last_login_id']],
SELECT * FROM login_log WHERE succeeded = 1 AND user_id = ? ORDER BY id DESC LIMIT 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment