patternsqlMinor
Database schema for a Minecraft logging plugin
Viewed 0 times
loggingminecraftdatabasepluginforschema
Problem
This is my attempt at creating a database schema for a Minecraft logging plugin. I'm by no means a SQL expert, so suggestions would be greatly appreciated.
``
--
DROP TABLE IF EXI
``
--
-- Table structure for table actions
--
DROP TABLE IF EXISTS actions;
CREATE TABLE IF NOT EXISTS actions (
id tinyint(3) unsigned NOT NULL,
name varchar(32) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY name (name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table actors
--
DROP TABLE IF EXISTS actors;
CREATE TABLE IF NOT EXISTS actors (
id mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
name varchar(32) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY name (name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table materials
--
DROP TABLE IF EXISTS materials;
CREATE TABLE IF NOT EXISTS materials (
id smallint(5) unsigned NOT NULL,
namespace varchar(64) NOT NULL,
name varchar(128) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY name (name,namespace)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table world_blocks
--
DROP TABLE IF EXISTS world_blocks;
CREATE TABLE IF NOT EXISTS world_blocks (
id int(10) unsigned NOT NULL,
datetime datetime NOT NULL,
actionid tinyint(3) unsigned NOT NULL,
actorid mediumint(8) unsigned NOT NULL,
x mediumint(9) NOT NULL,
y smallint(6) NOT NULL,
z mediumint(9) NOT NULL,
blockid smallint(5) unsigned NOT NULL,
PRIMARY KEY (id),
KEY datetime (datetime),
KEY actorid (actorid),
KEY coordinates (x,z,y),
KEY blockid (blockid),
KEY actionid (actionid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table world_entities`--
DROP TABLE IF EXI
Solution
Your Table Declarations are a little redundant with the
The SQL Engine is going to do an extra search to see if the table exists when we already know that if it existed it was dropped.
If you have a large Table the Drop is going to take some time in itself. If you have a large Database it is going to take at least a little bit of time looking for a table that we already know doesn't exist.
I would just change it to
I know this is just to set up the Database itself. but that was the only thing that sort of bugged me about your code
with your
DROP TABLE if it exists and then CREATE TABLE if it doesn't exist.The SQL Engine is going to do an extra search to see if the table exists when we already know that if it existed it was dropped.
DROP TABLE IF EXISTS `actors`;
CREATE TABLE IF NOT EXISTS `actors` (...If you have a large Table the Drop is going to take some time in itself. If you have a large Database it is going to take at least a little bit of time looking for a table that we already know doesn't exist.
I would just change it to
DROP TABLE IF EXISTS 'actors';
CREATE TABLE 'actors';I know this is just to set up the Database itself. but that was the only thing that sort of bugged me about your code
with your
NOT NULL's in your tables world_blocks and world_entities and world_items for the coordinates, I don't play Minecraft (please don't judge) but I imagine that you have to create a block in your inventory before adding it to the world. so you would have to have some coordinates attached to it if you are going to add it to the log before you actually add it to the world. (I hope that makes sense)Code Snippets
DROP TABLE IF EXISTS `actors`;
CREATE TABLE IF NOT EXISTS `actors` (...DROP TABLE IF EXISTS 'actors';
CREATE TABLE 'actors';Context
StackExchange Code Review Q#32655, answer score: 4
Revisions (0)
No revisions yet.