Bug #47009 The basic algorithm for table scan in plgin API is not actual.
Submitted: 31 Aug 2009 9:30 Modified: 18 Jan 2010 14:17
Reporter: Horst Hunger Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:azalea OS:Any
Assigned to: MC Brown CPU Architecture:Any
Tags: API, plugin, table scan

[31 Aug 2009 9:30] Horst Hunger
Description:
The following sequence of API calls is not more clear and needs to be acualized:
...
The following shows the method calls made during a nine-row table scan of the CSV engine: 
ha_tina::store_lock
ha_tina::external_lock
ha_tina::info
ha_tina::rnd_init
ha_tina::extra - ENUM HA_EXTRA_CACHE   Cache record in HA_rrnd()
ha_tina::rnd_next
ha_tina::rnd_next
ha_tina::rnd_next
ha_tina::rnd_next
ha_tina::rnd_next
ha_tina::rnd_next
ha_tina::rnd_next
ha_tina::rnd_next
ha_tina::rnd_next
ha_tina::extra - ENUM HA_EXTRA_NO_CACHE   End caching of records (def)
ha_tina::external_lock
ha_tina::extra - ENUM HA_EXTRA_RESET   Reset database to after open
...

When implementing the table scan like this without copying the code from CSV, then always the last row got lost. The very important information, that the last rnd_next must not contain values, but only the EOF is missing.

How to repeat:
int ha_tse::rnd_next(uchar *buf)
{
  int rc= 0;
  DBUG_ENTER("ha_tse::rnd_next");
  int size;
  int i;
  int line_begin;
  int line_end;
...
  for (Field **field=table->field ; *field ; field++)
  {
...
  }
...
  if (next_position >= local_saved_data_file_length)
      DBUG_RETURN(HA_ERR_END_OF_FILE);
  stats.records++;
  next_position= line_begin;
  DBUG_RETURN(rc);
}

instead of 

int ha_tse::rnd_next(uchar *buf)
{
  int rc= 0;
  DBUG_ENTER("ha_tse::rnd_next");
  int size;
  int i;
  int line_begin;
  int line_end;
...
  if (next_position >= local_saved_data_file_length)
      DBUG_RETURN(HA_ERR_END_OF_FILE);
...
  for (Field **field=table->field ; *field ; field++)
  {
...
  }
...
  stats.records++;
  next_position= line_begin;
  DBUG_RETURN(rc);
}

Suggested fix:
Change the following algorithm as follows:
..
The following shows the method calls made during a nine-row table scan of the:

store_lock
external_lock
info
rnd_init
extra - ENUM HA_EXTRA_CACHE   Cache record in HA_rrnd()
rnd_next
rnd_next
rnd_next
rnd_next
rnd_next
rnd_next
rnd_next
rnd_next
rnd_next
rnd_next (delivers only HA_ERR_END_OF_FILE, no values)
extra - ENUM HA_EXTRA_NO_CACHE   End caching of records (def)
external_lock
extra - ENUM HA_EXTRA_RESET   Reset database to after open
[31 Aug 2009 9:58] Sveta Smirnova
Thank you for the report.

But why category is "MySQL Forge"? Do you want more documentation regarding this topic or do you want SE API is changed?
[31 Aug 2009 16:48] Philip Stoev
The correct category for such bugs is Documentation.

The MySQL Forge category is only for bugs on the web engine that drives the Forge web site.
[18 Jan 2010 14:17] MC Brown
This bug has been promoted to a WorkLog item, and is now part of: 

http://forge.mysql.com/worklog/task.php?id=5228