Slow Performance lazarus / 16-Databases ---------------------------------------------------------------------- lucasperatelli · 2023-07-06 14:38 Hello, i am new at lazarus and i dealing with a issue with my system. On a specific search screen, I have a DBGrid component, that where I pass the SQL with filters (WHERE) to retrieve a maximum of 100 rows. Although the table without filters contains around 15,000 to 16,000 records, the execution and scrolling works fine once the DBGrid is populated, however, as soon as I click on a record/row, the performance becomes extremely slow, affecting both scrolling and selecting new records. But, the lag disappears instantly when I set the focus away from the grid to another component. A senior that i know suggested that this might be related to the cursor on the database records. I'm unsure if this is relevant, but I am working on the localhost, using PostgreSQL. Has anyone experienced a similar issue? Thank you in advance. ---------------------------------------------------------------------- Leledumbo · 2023-07-06 19:16 100 is a very little data, even the full 15000-16000 data is, and DBGrid is one of the most used component when making db application, so it's unexpected. The examples folder has database/sqldbtutorial3 which contains a project from a tutorial in the wiki. Can you reproduce the issue there? Does it happen only if you set the filter? ---------------------------------------------------------------------- Zvoni · 2023-07-07 06:50 Quote from: lucasperatelli on July 06, 2023, 04:38:32 pm*snip*... however, as soon as I click on a record/row, the performance becomes extremely slow, affecting both scrolling and selecting new records. .....*snip* Do you have any code inside OnClick and similiar events? ---------------------------------------------------------------------- lucasperatelli · 2023-07-07 11:03 Quote from: Zvoni on July 07, 2023, 08:50:10 amQuote from: lucasperatelli on July 06, 2023, 04:38:32 pm*snip*... however, as soon as I click on a record/row, the performance becomes extremely slow, affecting both scrolling and selecting new records. .....*snip* Do you have any code inside OnClick and similiar events? No, its a form just for that dbgrid, i put a debug point in every single procedure on the form, and doens't call. ---------------------------------------------------------------------- lucasperatelli · 2023-07-07 11:04 Quote from: Leledumbo on July 06, 2023, 09:16:14 pm100 is a very little data, even the full 15000-16000 data is, and DBGrid is one of the most used component when making db application, so it's unexpected. The examples folder has database/sqldbtutorial3 which contains a project from a tutorial in the wiki. Can you reproduce the issue there? Does it happen only if you set the filter? yeah, i know, 100 rows is not suposed to lag the way is lagging, i have way more dbgrid's where this lag doesn't happen, its just on this table with 15k rows, even with the 'where', that returns to me 100 rows, if i change the sql, even if it returns to me more than 100 rows, i have a sql that returns to me 2k rows and doesn't lag on that way ---------------------------------------------------------------------- marcov · 2023-07-07 12:20 Maybe a where that involves an unindexed field? ---------------------------------------------------------------------- Zvoni · 2023-07-07 12:25 Quote from: marcov on July 07, 2023, 02:20:39 pmMaybe a where that involves an unindexed field? In that case, shouldn't the "lag" occur before the result is loaded into the DBGrid? My Money is on code in an event like OnSelection or similar ---------------------------------------------------------------------- lucasperatelli · 2023-07-07 13:55 Quote from: marcov on July 07, 2023, 02:20:39 pmMaybe a where that involves an unindexed field? this table has 2 columns, a integer code and a varchar desc, the integer is a primary key and i created a index on the varchar column, but i dont have sure what that means and what this does ---------------------------------------------------------------------- lucasperatelli · 2023-07-07 13:56 Quote from: Zvoni on July 07, 2023, 02:25:51 pmQuote from: marcov on July 07, 2023, 02:20:39 pmMaybe a where that involves an unindexed field? In that case, shouldn't the "lag" occur before the result is loaded into the DBGrid? My Money is on code in an event like OnSelection or similar As i said, my form has just 5 procedures, and no one is related to the grid, i created a debug point on every procedure that may be called but no, no one called, so i think its not a event or smth ---------------------------------------------------------------------- Leledumbo · 2023-07-08 15:43 Quote from: lucasperatelli on July 07, 2023, 03:55:27 pmthis table has 2 columns, a integer code and a varchar desc, the integer is a primary key and i created a index on the varchar column, but i dont have sure what that means and what this does A where clause will make use of index if the specified fields are indexed. Compound index will also be used if you use multiple indexed keys through and operator, for instance. You said it only happens to this table, but not others. Do others table also have similar number of rows? It's a bit difficult to debug without looking at the whole schema, I hate guessing game, but I put my bet something in the schema instead of the code.