FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Question about performance RowSet
Posts: 114
Joined: Fri Jul 21, 2006 07:15 PM

Question about performance RowSet

Posted: Thu Mar 14, 2024 08:02 PM
Hello all.
Code (fw): Select all Collapse
oCn:Rowset( "select field1, field2 to my table where field3 = 'x' " ) // [b]1.87 seconds[/b]

oCn:QueryResult( "select field1, field2 to my table where field3 = 'x' " ) // [b]0.21 seconds[/b]
that's right?

This difference in accumulated time when I need to obtain data from several tables for editing in multiple browsers becomes very large.
For example, when i have a button to "insert' a new record, is there other way editing data without RowSet object?

Thanks in advance.
FWH / xHarbour / BCC / MySql

Visual Studio / Harbour / DotNet Maui / C#
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM

Re: Question about performance RowSet

Posted: Fri Mar 15, 2024 03:02 AM
podria ser que:
Code (fw): Select all Collapse
oCn:QueryResult( "select field1, field2 to my table where field3 = 'x' " ) // 0.21 seconds
retorna un arreglo simple de datos
y que
Code (fw): Select all Collapse
oCn:Rowset( "select field1, field2 to my table where field3 = 'x' " ) // 1.87 seconds
ac谩 creo que rao hace uso de una estructura de datos propia para poder hacer los filtrados y ordenamiento de forma local (cliente), para no hacer lecturas al servidor constantemente, aunado a que es un objeto bastante complejo, data/var y m茅todos, que es en lo cual donde realmente toma su tiempo, no tanto en la recuperaci贸n del cursor de datos que para ambos m茅todos es igual.

en lo personal, lo miro normal.

por eso cuando la informaci贸n que se pretende recuperar es poca, y una sola fila de datos es preferible usar QueryResult, no tiene sentido usar RowSet, dado que no se har谩 b煤squeda, ordenaciones, etc.

otro tip importantes es que, en un recordset, cuando usamos la asignaci贸n ( oQry:FIELD1 := 10 ) y lectura de un campo del query ( ?oQry:FIELD1 ), (tanto tmysq y tdolphin, en fwh no lo tengo claro ya que no se proporcionan los fuentes), se hace uso del m茅todo error para poder asignar y recuperar la informaci贸n y eso agrega tiempo adicional, ac谩 Rao podr铆a aclarar.
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM

Re: Question about performance RowSet

Posted: Fri Mar 15, 2024 03:15 AM

Otro tip adicional es que cuando hacemos una consulta al servidor, la primera vez tomo su tiempo, dado que esa info no existe en la cache del servidor, si en poco tiempo se hace una consulta similar, el tiempo de respuesta se reduce dado que mucha de la info ya est谩 en cache, esto ya es parte de la optimizaci贸n propia del servidor mysql/mariadb.

Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 114
Joined: Fri Jul 21, 2006 07:15 PM

Re: Question about performance RowSet

Posted: Fri Mar 15, 2024 01:50 PM
carlos vargas wrote:podria ser que:
Code (fw): Select all Collapse
oCn:QueryResult( "select field1, field2 to my table where field3 = 'x' " ) // 0.21 seconds
retorna un arreglo simple de datos
y que
Code (fw): Select all Collapse
oCn:Rowset( "select field1, field2 to my table where field3 = 'x' " ) // 1.87 seconds
ac谩 creo que rao hace uso de una estructura de datos propia para poder hacer los filtrados y ordenamiento de forma local (cliente), para no hacer lecturas al servidor constantemente, aunado a que es un objeto bastante complejo, data/var y m茅todos, que es en lo cual donde realmente toma su tiempo, no tanto en la recuperaci贸n del cursor de datos que para ambos m茅todos es igual.

en lo personal, lo miro normal.

por eso cuando la informaci贸n que se pretende recuperar es poca, y una sola fila de datos es preferible usar QueryResult, no tiene sentido usar RowSet, dado que no se har谩 b煤squeda, ordenaciones, etc.

otro tip importantes es que, en un recordset, cuando usamos la asignaci贸n ( oQry:FIELD1 := 10 ) y lectura de un campo del query ( ?oQry:FIELD1 ), (tanto tmysq y tdolphin, en fwh no lo tengo claro ya que no se proporcionan los fuentes), se hace uso del m茅todo error para poder asignar y recuperar la informaci贸n y eso agrega tiempo adicional, ac谩 Rao podr铆a aclarar.
Thank you Carlos.
FWH / xHarbour / BCC / MySql

Visual Studio / Harbour / DotNet Maui / C#
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Question about performance RowSet

Posted: Sat Mar 16, 2024 10:20 AM
RowSet
RowSet takes a bit more time, because during creation it collects a lot other relevant information which makes usage faster.
First time reading is a bit slower when compared to other libraries.
Once opened, updates, inserts, deletes, sorts, filters, etc. are all extremely faster than the other libs.
If we look back in the forums, we posted speed comparison with other libraries a few years back.

When a RowSet is opened for ReadOnly, again the initial reading is faster.
Code (fw): Select all Collapse
oRs := oCn:RowSet( cSql, [aParams], [lReadOnly] )
Execute
Code (fw): Select all Collapse
aData := oCn:Execute( cSql, [aParams] )
We get the data in a multi-dimensional array.
In case we need the structure, call this immediately
Code (fw): Select all Collapse
aStruct := oCn:Execute()
QueryResult
This is an extension to Execute.
if we use an sql like "select age from customer where id = 100"
this function returns 58, instead of {{58}}

As you indicated above, if we want to edit just one record in a table, we can
Code (fw): Select all Collapse
aRow := oCn:QueryResult( "select * from states where code='WA'" )
//We get a single dim array { "WA", "Washington" }
// Edit the array and then
oCn:Upsert( "states", nil, { aRow } )
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Question about performance RowSet

Posted: Sat Mar 16, 2024 01:18 PM
when i have a button to "insert' a new record, is there other way editing data without RowSet object?
Please try this and let us know.
Code (fw): Select all Collapse
 聽 oData := TArrayData():New( oCn, "select * from <tablename> limit 1" )
聽 聽oData:Record(,.t.):Edit()
聽 聽oData:SaveData()
I am thinking of adding method to get a single record from a table ( existing or new ) and then edit and save the data.
May be something like this:
Code (fw): Select all Collapse
oRecord := oCn:Record( cSql, [lBlank] ) // returns FW_Record / TDataRow object
oRecord:Edit()
Regards



G. N. Rao.

Hyderabad, India
Posts: 114
Joined: Fri Jul 21, 2006 07:15 PM

Re: Question about performance RowSet

Posted: Wed Mar 20, 2024 01:35 PM
Mr Rao, thank you for tyour attention and informattions.
nageswaragunupudi wrote:RowSet
RowSet takes a bit more time, because during creation it collects a lot other relevant information which makes usage faster.
First time reading is a bit slower when compared to other libraries.
Once opened, updates, inserts, deletes, sorts, filters, etc. are all extremely faster than the other libs.
If we look back in the forums, we posted speed comparison with other libraries a few years back.

When a RowSet is opened for ReadOnly, again the initial reading is faster.
Code (fw): Select all Collapse
oRs := oCn:RowSet( cSql, [aParams], [lReadOnly] )
Execute
Code (fw): Select all Collapse
aData := oCn:Execute( cSql, [aParams] )
We get the data in a multi-dimensional array.
In case we need the structure, call this immediately
Code (fw): Select all Collapse
aStruct := oCn:Execute()
QueryResult
This is an extension to Execute.
if we use an sql like "select age from customer where id = 100"
this function returns 58, instead of {{58}}
That is ok, works fine.
FWH / xHarbour / BCC / MySql

Visual Studio / Harbour / DotNet Maui / C#
Posts: 114
Joined: Fri Jul 21, 2006 07:15 PM

Re: Question about performance RowSet

Posted: Wed Mar 20, 2024 01:46 PM
nageswaragunupudi wrote: As you indicated above, if we want to edit just one record in a table, we can
Code (fw): Select all Collapse
aRow := oCn:QueryResult( "select * from states where code='WA'" )
//We get a single dim array { "WA", "Washington" }
// Edit the array and then
oCn:Upsert( "states", nil, { aRow } )
Mr Rao, this works when there exists any record from select.
When the select there no result, insert does not work.

I am try this:
Code (fw): Select all Collapse
aRow := oCn:QueryResult( "select field1,field2 from states where code='WA'" )
if aRow == NIL // not found, then inserts
聽 聽 aRow := { "aa","bb" } 
聽 聽 oCn:Upsert( "states", nil, { aRow } )
endif
But insert not work.

I have many processes for generating payroll for workers (40 thousand workers) in which the above situation occurs.
FWH / xHarbour / BCC / MySql

Visual Studio / Harbour / DotNet Maui / C#
Posts: 114
Joined: Fri Jul 21, 2006 07:15 PM

Re: Question about performance RowSet

Posted: Wed Mar 20, 2024 01:50 PM
nageswaragunupudi wrote:
when i have a button to "insert' a new record, is there other way editing data without RowSet object?
Please try this and let us know.
Code (fw): Select all Collapse
 聽 oData := TArrayData():New( oCn, "select * from <tablename> limit 1" )
聽 聽oData:Record(,.t.):Edit()
聽 聽oData:SaveData()
This code generated a runtime error:
Code (fw): Select all Collapse
C贸digo 聽 聽 聽 聽 聽 : 1
Descri莽茫o do Erro:
Erro BASE/1123 聽Erro nos par茠metros: AADD
C贸digo: 1
Detalhamento:
------------
Arg. 1 聽 聽 聽Tipo: U Valor: 
Arg. 2 聽 聽 聽Tipo: N Valor: 1

Chamada de Pilha
================
Chamado de AADD(0)
Chamado de (b)TARRAYDATA:LOADMYSQL(618)
Chamado de AEVAL(0)
Chamado de TARRAYDATA:LOADMYSQL(618)
Chamado de TARRAYDATA:FROMQUERY(456)
Chamado de TARRAYDATA:FROMMYSQL(366)
Chamado de TARRAYDATA:NEW(255)
FWH / xHarbour / BCC / MySql

Visual Studio / Harbour / DotNet Maui / C#
Posts: 114
Joined: Fri Jul 21, 2006 07:15 PM

Re: Question about performance RowSet

Posted: Wed Mar 20, 2024 01:52 PM
nageswaragunupudi wrote:
I am thinking of adding method to get a single record from a table ( existing or new ) and then edit and save the data.
May be something like this:
Code (fw): Select all Collapse
oRecord := oCn:Record( cSql, [lBlank] ) // returns FW_Record / TDataRow object
oRecord:Edit()
This would be very good, I believe, for many programmers.

Thany you Mr Rao.
FWH / xHarbour / BCC / MySql

Visual Studio / Harbour / DotNet Maui / C#
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Question about performance RowSet

Posted: Wed Mar 20, 2024 03:19 PM
I am try this:
Code:
aRow := oCn:QueryResult( "select field1,field2 from states where code='WA'" )
if aRow == NIL // not found, then inserts
aRow := { "aa","bb" }
oCn:Upsert( "states", nil, { aRow } )
endif


But insert not work.
Table `states` has 3 fields: id, code, name where id is autoincrement field

This should work:
Code (fw): Select all Collapse
oCn:Upsert( "states", nil, { { 0, "KK", "KState" } } )
For Upsert() to work, we need to include primary key also.

But you can use normal Insert like this:
Code (fw): Select all Collapse
oCn:Insert( "states", "code,name", { { "KK", "KKKK" } } )
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Question about performance RowSet

Posted: Wed Mar 20, 2024 04:45 PM
Please try this for adding new record.
This is working for me and should work for you too.
First run this program as it is without changes before you adopt to your tables.
Code (fw): Select all Collapse
function MariaNewRecord()

聽 聽local oCn := maria_Connect( "209.250.245.152,fwh,fwhuser,FiveTech@2022" )
聽 聽local oData

聽 聽oData := TArrayData():New( oCn, "states", "FALSE" )
聽 聽oData:Edit()
聽 聽oData:SaveBatch()

聽 聽xbrowser ocn:states

return nil
Regards



G. N. Rao.

Hyderabad, India
Posts: 114
Joined: Fri Jul 21, 2006 07:15 PM

Re: Question about performance RowSet

Posted: Wed Mar 20, 2024 07:01 PM
Hello Mr. Rao.
nageswaragunupudi wrote:I am try this:
Code (fw): Select all Collapse
aRow := oCn:QueryResult( "select field1,field2 from states where code='WA'" )
if aRow == NIL // not found, then inserts
聽 聽 aRow := { "aa","bb" }
聽 聽 oCn:Upsert( "states", nil, { aRow } )
endif
But insert not work.
Table `states` has 3 fields: id, code, name where id is autoincrement field

This should work:
Code (fw): Select all Collapse
oCn:Upsert( "states", nil, { { 0, "KK", "KState" } } )
For Upsert() to work, we need to include primary key also.
My table have 20 fields, but in this part of process I need edit or insert just a few.
nageswaragunupudi wrote:But you can use normal Insert like this:
Code (fw): Select all Collapse
oCn:Insert( "states", "code,name", { { "KK", "KKKK" } } )
Works, faster, I can use it. thank you!
FWH / xHarbour / BCC / MySql

Visual Studio / Harbour / DotNet Maui / C#
Posts: 114
Joined: Fri Jul 21, 2006 07:15 PM

Re: Question about performance RowSet

Posted: Wed Mar 20, 2024 07:07 PM
nageswaragunupudi wrote:Please try this for adding new record.
This is working for me and should work for you too.
First run this program as it is without changes before you adopt to your tables.
Code (fw): Select all Collapse
function MariaNewRecord()

聽 聽local oCn := maria_Connect( "209.250.245.152,fwh,fwhuser,FiveTech@2022" )
聽 聽local oData

聽 聽oData := TArrayData():New( oCn, "states", "FALSE" )
聽 聽oData:Edit()
聽 聽oData:SaveBatch()

聽 聽xbrowser ocn:states

return nil
Run time error:
Code (fw): Select all Collapse
C贸digo 聽 聽 聽 聽 聽 : 1
Descri莽茫o do Erro:
Erro BASE/1081 聽Erro nos par茠metros: +
C贸digo: 1
Detalhamento:
------------
Arg. 1 聽 聽 聽Tipo: C Valor: 聽where 
Arg. 2 聽 聽 聽Tipo: O Valor: TARRAYDATA

Chamada de Pilha
================
Chamado de TARRAYDATA:LOADMYSQL(607)
Chamado de TARRAYDATA:FROMMYSQL(391)
Chamado de TARRAYDATA:NEW(255)
Chamado de MARIANEWRECORD(190)
FWH / xHarbour / BCC / MySql

Visual Studio / Harbour / DotNet Maui / C#
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Question about performance RowSet

Posted: Wed Mar 20, 2024 08:22 PM
Run time error:
Which version of FWH did you test with please?
Regards



G. N. Rao.

Hyderabad, India