title: Emulating row_number when querying a view significantly effects performance
body: <p>I need a <code>row_number</code> field on result query when querying a View.</p>
  
  <p>Somehow the query takes a huge amount of time to run compared to querying the same view.</p>
  
  <p>Without <code>row_number</code> it takes around 200ms and with <code>row_number</code> it takes 30s to run.</p>
  
  <p>Our DB version does not support <code>ROW_NUMBER()</code> syntax. So I am currently implementing the same functionality with</p>
  
  <pre class="lang-sql prettyprint-override"><code>(@row_number:=@row_number + 1) AS row_number
  </code></pre>
  
  <p>The query I'm trying to run</p>
  
  <pre class="lang-sql prettyprint-override"><code>SET @row_number = 0;
  SELECT *, (@row_number:=@row_number + 1) AS row_number FROM some_view;
  </code></pre>
  
  <p>View definition</p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE 
      ALGORITHM = UNDEFINED 
      DEFINER = `user`@`%` 
      SQL SECURITY DEFINER
  VIEW `some_view` AS
      SELECT 
          `some_table`.`field1` AS `field1`,
          `some_table`.`field2` AS `field2`,
          `some_table`.`field3` AS `field3`,
          `some_table`.`field4` AS `field4`,
          CAST(JSON_EXTRACT(`some_table`.`json_data`,'$.field5') AS SIGNED) AS `field5`,
          JSON_UNQUOTE(JSON_EXTRACT(`some_table`.`json_data`, '$.field6')) AS `field6`,
          JSON_UNQUOTE(JSON_EXTRACT(`some_table`.`json_data`, '$.field7')) AS `field7`,
          JSON_UNQUOTE(JSON_EXTRACT(`some_table`.`json_data`,'$.field8.name')) AS `field8`
      FROM
          `some_table`
  </code></pre>
  
  <p>expected to get a reasonable runtime for this query</p>