Different behavior of CreateIndexes method

Home Forums kbmMemTable Different behavior of CreateIndexes method

Tagged: 

  • This topic has 2 replies, 2 voices, and was last updated 1 week, 2 days ago by kimbomadsen.
Viewing 2 reply threads
  • Author
    Posts
    • #55956
      Alejandro
      Participant

      Hi,

      TkbmMemTable’s CreateIndexes method bahaves differently in 7.62.00 as opposed to 5.01 when creating indexes in a table that has existing records.

      In 5.01, the following code would result in a fully populated table, but in 7.62.00 it ends up empty.

      The functionality was particularly useful when adding an index to an existing table which contained records was necessary. Now we first need to do a copy of the records somewhere else, create the index and then copy the records back to the original table, which seems to end up using additional memory and time. We also need to modify the existing code to cover for the different functionality.

      Is it be possible to achieve the previous original functionality with the current version of the component? Would it be possible with a different approach? Is this considered a bug?

      Thanks in advance.

      procedure TForm1.Button1Click(Sender: TObject);
      begin
      kbmMemTable1 := TkbmMemTable.Create(Self);

      kbmMemTable1.FieldDefs.Add(‘ID’, ftInteger);
      kbmMemTable1.FieldDefs.Add(‘NAME’, ftString, 50);
      kbmMemTable1.CreateTable;

      kbmMemTable1.Active := True;

      kbmMemTable1.AppendRecord([1, ‘A’]);
      kbmMemTable1.AppendRecord([2, ‘B’]);
      kbmMemTable1.AppendRecord([1, ‘A’]);
      kbmMemTable1.AppendRecord([2, ‘B’]);

      DataSource1.DataSet := kbmMemTable1;
      end;

      procedure TForm1.Button2Click(Sender: TObject);
      begin
      kbmMemTable1.IndexDefs.Add(‘idx1’, ‘ID;NAME’, [ixCaseInsensitive]);
      kbmMemTable1.CreateIndexes;
      kbmMemTable1.IndexName := ‘idx1’;
      end;

       

    • #55958
      Alejandro
      Participant

      Alright, browsing the forum I found about the ‘SortOn’ method, which lead me to (hopefully) the correct solution to our previous non functional code.

      We’d still need to modify the code, but with no performance inpact.

      procedure TForm1.Button2Click(Sender: TObject);
      var a: TkbmIndex;
      begin
      // kbmMemTable1.SortOn(‘ID;NAME’, [mtcoCaseInsensitive]);
      a := kbmMemTable1.AddIndex(‘idx1’, ‘ID;NAME’, [ixCaseInsensitive]);
      a.Rebuild;
      kbmMemTable1.SwitchToIndex(a);
      // kbmMemTable1.IndexDefs.Add(‘idx1’, ‘ID;NAME’, [ixCaseInsensitive]);
      // kbmMemTable1.CreateIndexes;
      // kbmMemTable1.IndexName := ‘idx1’;
      end;

      Thanks in advance.

    • #56038
      kimbomadsen
      Keymaster

      A difference between the old v5 and the later versions is that the later versions supports indexes based on other indexes, which generally provides way faster performance during range, filtering etc. operations in combination with ordering or grouping.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.