Recent

Author Topic: BUG ? searching in dbgrid with indexed column is not logarithmic ?  (Read 6412 times)

jimbill

  • New Member
  • *
  • Posts: 11
Hello Everyone,

I cant speak very well :)

Lazarus is very good tool.
Congratulations to the developers. And so forth

I would like to announce an error.

If i have a dbgrid connect with datasource connect with ztable (zeos component)
and I set in the object inspector (of ztable) IndexFieldNames to the database table column which is indexed
and i have for exemaple 100 000 elments in the table and I want to search in this table (for one
field) I see a very slow linear search not logaritmic.

Is there implemented indexed searching in dbgrid or not?

seeking in this way: stroke of each letter do searching (for name)

 DBGrid1.DataSource.DataSet.Locate('product',Edit1.Text,[LoPartialKey,loCaseInsensitive]);


sqlite3
ZEOSDBO-7.1.4-stable

windows 7/32 bit
lazarus 1.4.2  i386-win32-win32/win64


Any help welcome :).

Thanks,
Jimbill
« Last Edit: August 30, 2015, 02:44:08 am by jimbill »

derek.john.evans

  • Guest
Re: BUG ? searching in dbgrid with indexed column is not logarithmic ?
« Reply #1 on: August 30, 2015, 09:03:39 am »
Wouldn't that be a TDataSet issue, ie: ZTable?

rvk

  • Hero Member
  • *****
  • Posts: 6171
Re: BUG ? searching in dbgrid with indexed column is not logarithmic ?
« Reply #2 on: August 30, 2015, 11:28:21 am »
Yes, this has nothing to do with tdbgid but how you're using ztable.

You say you have set IndexFieldNames to the indexed field. Is that field "product"? If not than that could be your problem. You are using locate() on field "product" to locate a record so you should have an index on field "product" in your database. Is there?
« Last Edit: August 30, 2015, 11:30:09 am by rvk »

bylaardt

  • Sr. Member
  • ****
  • Posts: 309
Re: BUG ? searching in dbgrid with indexed column is not logarithmic ?
« Reply #3 on: August 31, 2015, 03:05:23 am »
your "order by" from tdataset match with the "dataset.locate" field?

if not, find your product ID with another select and locate with the result (order by field) of the second select.

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: BUG ? searching in dbgrid with indexed column is not logarithmic ?
« Reply #4 on: August 31, 2015, 07:49:34 am »
I am not a expert for Zeos components, but I guess, that Locate is performed on local buffered dataset stored on client side. So it has nothing with index defined on table on server side.
(this index is not useable by Zeos, ZTable)

miab3

  • Full Member
  • ***
  • Posts: 145
Re: BUG ? searching in dbgrid with indexed column is not logarithmic ?
« Reply #5 on: August 31, 2015, 03:27:39 pm »
You are using a local dataset.
To accelerate locate set SortedFields on 'product' or use Query as others suggest.

Michal
« Last Edit: August 31, 2015, 03:36:32 pm by miab3 »

miab3

  • Full Member
  • ***
  • Posts: 145
Re: BUG ? searching in dbgrid with indexed column is not logarithmic ?
« Reply #6 on: September 01, 2015, 05:10:15 pm »
Besides locate and  query select you can use Filter/Filtered
For example:

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
ZTable1.Locate('product','a',[LoPartialKey,loCaseInsensitive])
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
ZTable1.Filtered:=false;
ZTable1.Filter:='product like ''a*''';
ZTable1.Filtered:=true;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
ZTable1.Filtered:=false;
ZTable1.Filter:='product >= ''a'' and product < ''b''';
ZTable1.Filtered:=true;
end;

Michal

miab3

  • Full Member
  • ***
  • Posts: 145
Re: BUG ? searching in dbgrid with indexed column is not logarithmic ?
« Reply #7 on: September 06, 2015, 09:30:41 pm »
Code: [Select]
With ZQuery1 do Begin
       Sql.Clear;
       SQL.Text := 'SELECT product FROM products WHERE product >= :x LIMIT 10;';
       Params.ParamByName('x').AsString := Edit1.Text;
//       ExecSql;  <-- is not needed
       Open;
    end; 

Michal

 

TinyPortal © 2005-2018