INDEX on / seek in MARIA DB

INDEX on / seek in MARIA DB

Postby mauri.menabue » Thu May 18, 2023 8:11 am

Hi All
how do you create an index with multiple fields in Maria Db and then also the seek command

with DBF Es. Index ON COD_CLI + STR(COD_NUM,2) ... with MARIA DB ..........................
CLIENT->(dbseek(COD_CLI+str(COD_NUM,2))) with MARIA DB oRS:seek(COD_CLI, COD_NUM) correct ?

tia
User avatar
mauri.menabue
 
Posts: 155
Joined: Thu Apr 17, 2008 2:38 pm

Re: INDEX on / seek in MARIA DB

Postby nageswaragunupudi » Thu May 18, 2023 10:02 am

In RDBMSs other than DBFs, indexes are not used for Navigation or for Seeks.
The purpose of indexes is only to optimize where clauses for queries.
Intelligent planning of indexes is an essential part of database design to optimize queries in OLAP (Online Analytical processing).
For the size of data tables most of use, no indexes are ever necessary. We need to think about them when we are dealing with multi-million records tables.

Now, as for Seek.
If you are using FWMariaDB for MySql or MariaDB, this works with single field.
Note: No indexes need to be build. Creating indexes is an unnecessary overhead.
Code: Select all  Expand view

oRs:SetOrder( "fieldname" )
oRs:Seek( uValue )
 


OR

Code: Select all  Expand view

oRs:SetOrder( "CITY ASC,SALARY DESC" )  // multicol sort
oRs:Seek( cValue ) // works only for first field. i.e., CITY
 


Now, your requirement is to seek on multi-field values.
We advise you to use oRs:Locate()
Code: Select all  Expand view

oRs:Locate( "CITY = 'N' .AND. AGE > 40" )
// for locating next
oRs:Locate( "CITY = 'N' .AND. AGE > 40",, .T. )
 


Note: With FWMariaDB, all sorting, seeking and locating are done in memory. Database is not acccessed or queried. Therefore these operations are very fast.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: INDEX on / seek in MARIA DB

Postby NWKL » Thu May 18, 2023 11:14 am

Mr Nages, where i can find one guide to migrate ads files to fwmaria, can i use the same syntax ?
i use ads and tdatabase, can i only convert and open files using fwmaria and use the code with syntax or i have to change all? i can use an local and server (embeded) like i use with ads?

thanks
best regards
NWKL
 
Posts: 26
Joined: Thu Aug 04, 2022 12:45 pm

Re: INDEX on / seek in MARIA DB

Postby shrifw » Thu May 18, 2023 4:03 pm

Hi ,

This can achieve using GENRATED COLUMNS in Maria DB. as given code below. The Given code is just an idea you have to modify the code to remove syntax errors.

Steps
1. Add Generated Column
2. Create Index on Generated Column


Code: Select all  Expand view


CREATE TABLE Employees (
  Id INTEGER PRIMARY KEY,
  FirstName VARCHAR(50),
  LastName VARCHAR(50),
  FullName VARCHAR(101) AS (CONCAT(FirstName, ' ', LastName))
);


ALTER TABLE Employees
  ADD FullName VARCHAR(101) GENERATED ALWAYS AS (CONCAT(FirstName, ' ', LastName)) STORED;
 
CREATE INDEX `names_idx` ON `Employees`(`FullName`);  


 


Thanks
Shridhar
shrifw
 
Posts: 69
Joined: Fri Aug 28, 2009 5:25 am

Re: INDEX on / seek in MARIA DB

Postby nageswaragunupudi » Fri May 19, 2023 1:07 pm

NWKL wrote:Mr Nages, where i can find one guide to migrate ads files to fwmaria, can i use the same syntax ?
i use ads and tdatabase, can i only convert and open files using fwmaria and use the code with syntax or i have to change all? i can use an local and server (embeded) like i use with ads?

thanks
best regards


First, please see
viewtopic.php?f=3&t=33286
for complete documentation of FWMariadb/MySql

It is very easy to import DBF files to MySql server using this library.

You can not totally use the same syntax for the entire application. You will need to make some changes.
Because you are now using TDatabase, you will find the new FWMariaRowSet class ( class to handle MySql tables ) very similar to TDatabase class. So changes should be less.

If you start. we will provide you the best possible support on the forums.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: INDEX on / seek in MARIA DB

Postby nageswaragunupudi » Fri May 19, 2023 1:09 pm

mauri.menabue wrote:Hi All
how do you create an index with multiple fields in Maria Db and then also the seek command

with DBF Es. Index ON COD_CLI + STR(COD_NUM,2) ... with MARIA DB ..........................
CLIENT->(dbseek(COD_CLI+str(COD_NUM,2))) with MARIA DB oRS:seek(COD_CLI, COD_NUM) correct ?

tia


We are thinking of sorting and seek on compound expressions.
We will announce this enhancement soon
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 104 guests