![]() |
SQL Lite
I've been reading around and noticed there has been an update that gives us access to a SQL lite database. This is a really nice addition to graal but I was wondering what the performance is like when your database gets bigger. I know that the old way of scripting, that we would store inventory specific variables on the player with clientr. We would also store economy using serverr. Should we replace this functionality with the sql queries?
|
It will perform better than anything Graal has built into it if you have a lot of data. If you only have small amounts of data (which I think classifies 99% of Graal), avoiding the overhead of SQLite is probably faster.
But it any case, it's an extra layer of complexity. Sometimes that complexity is required, and if you find yourself implementing data structures in GS2 to help you lookup data faster, then you should probably starting using SQLite since it's already done for you. It's also important to note here that it's really easy to suck at SQL (just like anything else) and make everything run slow as hell. You need to be careful with how you define your schema and queries, make sure to index properly (and sometimes even give up certain relational properties) in order to maximize speed. If you aren't careful you can definitely make stuff run slower than whatever you would do in GS2, probably. So in summary, it's another tool, and imo it only needs to be used when you have particularly large amounts of data, and when you do, you need to go read about a bunch of stuff regarding relational databases and proper schema design. |
SQL Advice: Make sure you learn about normalization (importantly learning up to 3rd normal form) if you want to be "good" at it.
I would recommend re-thinking your approach with the "serverr." values if you feel that SQL is a good alternative to it. Explain what exactly you're trying to do first please. |
Any form of SQL is only as fast as you make it. Data stored in SQLite tables is not stored in memory, so it takes longer to get that data. Depending on your scenario, you may want to cache this information in player variables. Some reasons for using SQLite for data storage are easy offline access, easy backup, organization, and easy querying/retrieving that data.
Ultimately if you decide to use SQLite, index it well and make sure you know how to use indexes. This page in particular may be helpful. Read section 1.1 carefully so you understand how the left-most column in indexes works; if you don't, your indexes won't do ****. |
Quote:
|
Quote:
|
Quote:
To refine it a little for anyone who is interested:
But even with this, if you need the guarantee that something will be in memory, it's a good idea to keep it in a regular ol' client variable since you may not want the lag if the data is cold and its needed for something important (e.g., sword strength or something which needs to be there in real time). But yeah, complexity. It may not be worth all this. |
Quote:
Hopefully if I keep this simple and everything organized it will all fall into place. |
Quote:
It's written in C, so it's implementation of a B-Tree will be far faster than anything you could do in GS2. Most of the time your entire dataset will be loaded into SQLite's memory anyways so you don't really need to worry about the disk. |
Quote:
For example, if you have a bank, and you want to find every account with over $5000 in the bank, you can run a query "SELECT * FROM bank WHERE money > 5000 ORDER BY money DESC". The equivalent code using a DBNPC would be something like PHP Code:
The performance issues are not that big, either. Quote:
|
Quote:
edit: .7 seconds faster, actually =p just tested it myself, and adding 70k rows took 3.4 seconds. So minus .7 is ~2.7 seconds. I also tested storing the values in the DBNPC instead of a SQLite table, and it took ~15 seconds So yeah, when used properly, SQLite is a beast. |
Also note that inserting the rows then creating the index after that will be faster, probably, if you feel like optimizing that benchmark.
|
| All times are GMT +2. The time now is 01:58 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.