That is the point. Imagine in attempt 5, you want to search for all games that has a position after d4-d5, and is played by grand masters. You get 40000 games. Now you send the second query containing 40000 game IDs, and unfortunately there is no easy way to do that.phhnguyen wrote: ↑Thu Dec 23, 2021 3:07 amAt the moment the database doesn’t store FENs but hash keys thus you can’t query using FENs directly. You need to convert the given FEN to a hash key first. You can find the function makehash in our code to do that task. Or you can use any function from the 3rd parties since we are using hash keys as Polyglot (opening books) ones.Sopel wrote: ↑Wed Dec 22, 2021 12:52 pmThis doesn't look right. Where's the comparison to the provided fen?phhnguyen wrote: ↑Tue Dec 21, 2021 10:49 pmDates are stored as TEXT, you may compare directly or use some build-in functions such as date(), strftime()...
For example (the last line):
Code: Select all
SELECT g.ID, g.Round, Date, w.Name White, WhiteElo, b.Name Black, BlackElo, Result, Timer, ECO, PlyCount, FEN, Moves FROM Games g INNER JOIN Players w ON WhiteID = w.ID INNER JOIN Players b ON BlackID = b.ID WHERE inResultSet(g.ID) AND Date > "2012-10-18"
Once you have a hash key you can start querying. The table HashPositions contains the info about hash keys and their corespondent game IDs. With game IDs you can get the game’s information (such as players, results, dates, moves…) from the table Games.
With the database of Attempt 4th, you may need only one query for all game information, using a SELECT-JOIN statement. With the database of Attempt 5th, you need two queries, the first one to get the game ID list (for the given hash key), the second one to query Games (for game information) with that list of game IDs.
There is a function named benchMatchingMoves in the code to measure the speed of querying positions. You may use it as a simple example of how to query chess positions.
While in attempt 4 (with pagination), you send one query, the db sends back one page (pagination is like limit, but you also get a handle to ask for the next pages). And that would be the end of it.
Databases are excellent tools for searching indexed data, lets use it and off load as much task as possible to them