title: Spring OAuth2 JDBCTokenStore performance and database schema
body: <p>I use MySQL5.5 + REST(Jersey) + Spring Security + Spring OAuth2. Right now I'm doing performance testing and noticed that </p>
  
  <p><code>org.springframework.security.oauth2.provider.token.store.JdbcTokenStore.readAuthentication</code> method is working really slow.. especialy this part of the method:</p>
  
  <pre><code>authentication = jdbcTemplate.queryForObject(selectAccessTokenAuthenticationSql,
                      new RowMapper&lt;OAuth2Authentication&gt;() {
                          public OAuth2Authentication mapRow(ResultSet rs, int rowNum) throws SQLException {
                              return deserializeAuthentication(rs.getBytes(2));
                          }
                      }, extractTokenKey(token));
  </code></pre>
  
  <p>In order to improve performance I'm going to add MySQL index to the following query:</p>
  
  <pre><code>private static final String DEFAULT_ACCESS_TOKEN_AUTHENTICATION_SELECT_STATEMENT = "select token_id, authentication from oauth_access_token where token_id = ?";
  </code></pre>
  
  <p>on <code>token_id</code> field but the main issue is that regarding the official oauth2 Spring database schema, for example <a href="https://github.com/spring-projects/spring-security-oauth/blob/master/spring-security-oauth2/src/test/resources/schema.sql" rel="nofollow noreferrer">https://github.com/spring-projects/spring-security-oauth/blob/master/spring-security-oauth2/src/test/resources/schema.sql</a></p>
  
  <pre><code>create table oauth_access_token (
    token_id VARCHAR(256),
    token LONGVARBINARY,
    authentication_id VARCHAR(256) PRIMARY KEY,
    user_name VARCHAR(256),
    client_id VARCHAR(256),
    authentication LONGVARBINARY,
    refresh_token VARCHAR(256)
  );
  </code></pre>
  
  <p><code>token_id</code> is <code>VARCHAR(256)</code> and due to a MySQL bugs or limitations I'm unable to add this index (for example <a href="https://stackoverflow.com/questions/20908928/mysql-specified-key-was-too-long">MySQL Specified key was too long</a>)..</p>
  
  <p>So my question is - is it mandatory to have <code>token_id</code> as <code>VARCHAR(256)</code> or I can change it to <code>VARCHAR(255)</code> ?</p>