Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Hash lookups, Database lookups, and Scalability

by mpeppler (Vicar)
on Oct 31, 2004 at 15:53 UTC ( [id://404138]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Hash lookups, Database lookups, and Scalability
in thread Hash lookups, Database lookups, and Scalability

There are various issues that enter into calculating the number of IOs. If the index covers the query (i.e. all the columns that are required for the output are part of the index), then only the index page/row needs to be read.

If a clustered index is used, then with Sybase 11.9.2 and later if the table uses "all pages" locking then the leaf index page and the data page are one and the same, but if the table uses "data only" locking (commonly referred to as DOL) then the index leaf pages and the data pages are separate.

Which all means that estimating the number of IOs for a particular query can be a lot of fun, and is the reason why cost-based optimizers (such as the one Sybase uses) are pretty complicated beasts...

Michael

Replies are listed 'Best First'.
Re^4: Hash lookups, Database lookups, and Scalability
by davido (Cardinal) on Oct 31, 2004 at 16:00 UTC

    I see that a properly constructed index is going to be vital for optimum performance. Given the criteria of the dual crossreferenced lookups, how might I better construct the indices in the code I posted? I'm curious to see if the DB solution can be better optimized.


    Dave

      Indexes and query behavior is usually pretty tied to the way a particular database engine works - and I don't know SQLlite at all, so I can't really help you with specifics.

      However, your table schema is exceedingly simple, so you really only have two choices:

      create unique index left_ix on words(left)
      or
      create unique index left_ix on words(left, right)
      (and their opposites).

      The first form is more "correct" - you really only want the key in the index. The second form may give you slightly better performance, at the expense of allowing duplicate "left" words into the table as long as they point at a different "right" word, and slightly more work during inserts (index maintenance is a little more complicated).

      Personally I'd use the first form (index on "left", and a separate index on "right").

      Michael

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://404138]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (9)
As of 2024-03-28 09:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found