• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Nymall

A few painful questions about Databases

9 posts in this topic

Using: MySQL, PHP, JQuerry

 

Well, I have a few questions about database organization and I'm hoping you guys can help me out. I'm not new to programming - I'm mostly self-taught, and I've been doing it on and off since I was in my early teens. However, I've been finding information about organizing things very hard to track down...

 

I guess I should give an example. Right now I'm working on the framework for a web game for my wife. It's real simple, image mapping, point and click stuff, but I'm having some difficulty figuring out how to plan ahead just in case this game is live in 5~10 years(as unlikely as it is). At the moment the inventory is split into seven different tables, with a total of 600 columns combined for all of them.The farther I'm getting into this project, the more I'm wondering if each character should have their own table, and rows for each of the items they have, or if I should proceed as I have done.

 

So, in summary - ?Is it more efficient to have a table with 600+ columns and 100,000+ rows, or 100,000+ tables with a average of 100 rows each? How much weight does a empty entry add to the database? Is there a easy way to future proof the minimalist number of table concept without it eventually getting completely unmanageable?

 

Now for problem number 2: I've got a bit of explaining first... Right now, when a user clicks a link, the game pulls the location the player is currently in and the number associated with the hotspot they clicked, and checks it against a table of valid destinations for that room. If there is a valid destination, it's returned to the script and the game makes another check to the database for the information for that room, which is then brought back to the script. From there, it enters a "flag section" which filters if the player can continue.

 

1)If it returns true, the scene draws as normal.

 

2)If it returns false, it checks the database for the new possible destination, and then renders that location as if it was the location initially returned.

 

The problem - This can at times mean that the database can be queried a total of five times for a simple move action.

 

Notes: There are some locations that are designed to have multiple tests running at the same time, by order, so it would add a lot of bulk to add the test information right into the scene table.

 

Is there any general advice you can give to shorten up this insanse number of database calls? Is there a faster way to script this in MySQL? Would the performance loss be fine for a small/medium sized game?

 

Thank you for your help!

0

Share this post


Link to post
Share on other sites

I'm not an expert in database management, but to me that number is too high for a database column or tables.

 

Have you ever heard about Dabatase Normalization? Simply, it's a concept of separating columns into tables and make relations to it. It's useful to avoid redundancy and dependency. It also will free your databases from some anomalies (deletion, update and insertion anomalies).

 

A character having a table just for its items is completely unnecessary. What if there's a new character? Making the same table (with only different names) over and over again is obviously redundant.

 

I'm wondering how could your database have that many tables and column. Can you please export your database and upload it here? That way I can analyze it and, if possible, make it more simple and effective. Trying to tweak something I can't see is hard. laugh.png

 

The row number is fine if the game is really big, but not for column and tables.

Edited by Sky Warden
0

Share this post


Link to post
Share on other sites

I'll try to answer your question:

 

 ?Is it more efficient to have a table with 600+ columns and 100,000+ rows, or 100,000+ tables with a average of 100 rows each? How much weight does a empty entry add to the database? Is there a easy way to future proof the minimalist number of table concept without it eventually getting completely unmanageable?

 

One large table is likely to be more efficient than 100,000 small tables simply because MySQL is a relational database and there could be significant overhead in chasing down primary and foreign keys for each access to a different table.

 

Empty entries should not add much weight to the database, but you should really wonder why you need them, are you simply trying to keep the dimensions of two tables similar in some way?

 

MySQL most likely uses some sort of logarithmic search algorithm to find entries (i.e. a binary search).

 

This search is extremely fast even for HUGE numbers. For instance a computer can find one name in a phonebook with 1,000,000 names in just 20 comparisons. So you shouldn't worry too much about the number of search queries you need to make. But if you insist on worrying, see if it's possible for you to batch them all together and make only one large query call through the API to reach MySQL and ask it to batch search many rows at once, because the time to issue the call and connect to MySQL might be slower than the time to search.

 

It's nice you are making a game for your wife. I agree with Sky Warden, you should share your usage of this database with us, because it sounds like possible overkill if you have 100,000 distinct tables.

Edited by Steve_Segreto
0

Share this post


Link to post
Share on other sites

One large table is likely to be more efficient than 100,000 small tables simply because MySQL is a relational database and there could be significant overhead in chasing down primary and foreign keys for each access to a different table

 

I think this can't be generalised so easy. tbh, 100,000 tables is a ridiculous number, but so is 1. Once your business logic becomes slightly complex you will run into various performance issues related to write locking, cache utilisation, index updates, etc.

 

"because MySQL is a relational database and there could be significant overhead in chasing down primary and foreign keys for each access to a different table".

 

This can be viewed from a different angle: Relational databases are highly optimised in dealing with relations. If your data can be modeled in a relational manner you should go for it. As Sky Warden suggested, OP should look up data normalisation.

 

Edit: The fastest database query is the one that doesn't happen. If you know you are going to read a lot of data in the future, you can preload it into an easier accessible storage. You could, for example, load the current room data the user is in into memory and check from there instead of constantly checking the database.

Edited by Madhed
0

Share this post


Link to post
Share on other sites

To re-iterate, you need to normalise your data. Generally speaking, databases have lots of rows in a relatively small number of tables with a small number of well defined columns.

 

... I'm having some difficulty figuring out how to plan ahead just in case this game is live in 5~10 years(as unlikely as it is).

If your data is well normalised it usually isn't incredibly difficult to migrate the schema should the need arise. Speculating too far ahead can cause all sorts of problems, not least finding out that what you need is not what you planned for.

1

Share this post


Link to post
Share on other sites

I agree with the others.  For example here is one way to normalize it:

 

 

character

========

id

name

 

attribute

======

id 

name

 

character_attribute

===============

id

attribute_id

attribute_value

 

unique index main_ind (id, attribute_id)

 

 

Your character_attribute table will now have 500 rows per character.    This is much more scalable and still easy to work with.  

 

edit:  Just to populate this a bit to further illustrate:

 

character table

===========

id , name

1 , Conan

2 , Gandalf

 

character_attribute  table

===================

id , name

1 , class

2 , level

3 , strength

4 , spellpower

 

character_attribute

==============

id , attribute_id,  attribute_value

1 , 1 , Warrior

1 , 2 , 15

1 , 2 , 18

1 , 2 , 0

2 , 1 , Wizard

2 , 2, 20

2 , 3 , 5

2 , 4 , 19

Edited by starbasecitadel
1

Share this post


Link to post
Share on other sites

Now for problem number 2: I've got a bit of explaining first... Right now, when a user clicks a link, the game pulls the location the player is currently in and the number associated with the hotspot they clicked, and checks it against a table of valid destinations for that room. If there is a valid destination, it's returned to the script and the game makes another check to the database for the information for that room, which is then brought back to the script. From there, it enters a "flag section" which filters if the player can continue.

 

1)If it returns true, the scene draws as normal.

 

2)If it returns false, it checks the database for the new possible destination, and then renders that location as if it was the location initially returned.

 

The problem - This can at times mean that the database can be queried a total of five times for a simple move action.

 

Notes: There are some locations that are designed to have multiple tests running at the same time, by order, so it would add a lot of bulk to add the test information right into the scene table.

 

Hmm... better designed and normalized database would really help here.

I do not know how exactly have you structured your database, but I'd most probably do something like this:

  • Table called RoomInfo which holds relevant information about each room.
  • Table called RoomLinks with attributes (colums) called CurrentRoom_ID, DestinationRoom1_ID, DestinationRoom2_ID etc.
  • When link is clicked, have the database return row from RoomLinks (based from current location) parallely joined with RoomInfo based on each ID. This removes the need of calling it once more because you can both check for valid destinations and immediately grab required data.

It's always faster to have separate tables (like rooms, hotspots, destinations) and just join them when called to get all the data you need in one call than to have one table which you need to call multiple times. There are various ways to join tables, depending on your needs.

Also note that this solution may not be perfect - after all, I'm just studying databases, maybe someone else can provide better insight.

0

Share this post


Link to post
Share on other sites

Now for problem number 2: I've got a bit of explaining first... Right now, when a user clicks a link, the game pulls the location the player is currently in and the number associated with the hotspot they clicked, and checks it against a table of valid destinations for that room. If there is a valid destination, it's returned to the script and the game makes another check to the database for the information for that room, which is then brought back to the script. From there, it enters a "flag section" which filters if the player can continue.



1)If it returns true, the scene draws as normal.



2)If it returns false, it checks the database for the new possible destination, and then renders that location as if it was the location initially returned.



The problem - This can at times mean that the database can be queried a total of five times for a simple move action.



Notes: There are some locations that are designed to have multiple tests running at the same time, by order, so it would add a lot of bulk to add the test information right into the scene table.



Is there any general advice you can give to shorten up this insanse number of database calls? Is there a faster way to script this in MySQL? Would the performance loss be fine for a small/medium sized game?

 

Please explain what sort of additional tests you need to run when the user tries to follow links. Basically, this is another many-to-many relationship, from rooms to rooms, with link-related data in the pivot table (e.g. room A is linked to room B through rectangular hotspot from x1,y1 to x2,y2 with caption S). You can get s list of a room's outgoing links very cheaply, then you only need to load room data for the entered room: what performance issues are you worrying about?

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0