Skip to content

Commit

Permalink
Implement LAST_INSERT_IDS function (#1469)
Browse files Browse the repository at this point in the history
Summary:
This is a multiple-value counterpart of the existing LAST_INSERT_ID function.
Its results are returned as a table.

- Hardcode the function name LAST_INSERT_IDS into the lexer and the parser due
  to how MySQL supports table-returning functions, patch the parser for the
  function.
- To keep the autoincrement value set efficiently, implement a data structure
  that 1) uses delta encoding for consecutive values; 2) special-cases encoding
  of consecutive delta equal to one values into a single number.
- Maintain the last_insert_ids set in THD for the previous and the current
  statement, similar to existing first_successful_insert_id_in_prev_stmt and
  first_successful_insert_id_in_cur_stmt fields.
- Add a main.last_insert_ids test.
- Since MyISAM is an engine that supports composite primary keys with
  autoincrement suffixes, this scenario is supported as well by allowing the
  values to be actually non-monotonic by delta encoding writing large deltas
  that make the value wrap around. For this case add a
  main.last_insert_ids_myisam test.

Pull Request resolved: #1469

Differential Revision: D60675155

fbshipit-source-id: c702048a14763db37140407c40f0d7ca648d5901
  • Loading branch information
laurynas-biveinis authored and facebook-github-bot committed Sep 3, 2024
1 parent adcb023 commit 00c726c
Show file tree
Hide file tree
Showing 16 changed files with 1,310 additions and 0 deletions.
1 change: 1 addition & 0 deletions mysql-test/r/information_schema_keywords.result
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ KILL 1
LAG 1
LANGUAGE 0
LAST 0
LAST_INSERT_IDS 1
LAST_VALUE 1
LATERAL 1
LEAD 1
Expand Down
Loading

0 comments on commit 00c726c

Please sign in to comment.