<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>MySQL Forums - Database Design and Data Modelling</title>
        <description>Forum to discuss the important topic of proper schema design.</description>
        <link>http://forums.mysql.com/list.php?125</link>
        <lastBuildDate>Fri, 24 May 2013 20:13:29 +0000</lastBuildDate>
        <generator>Phorum 5.2.19</generator>
        <item>
            <guid>http://forums.mysql.com/read.php?125,587186,587186#msg-587186</guid>
            <title>Error 1005 - ToyExample (1 reply)</title>
            <link>http://forums.mysql.com/read.php?125,587186,587186#msg-587186</link>
            <description><![CDATA[ Hey,<br />
<br />
while using a toy example i'm getting an error 1005 without any idea how to fix it, or concrete where the problem is located..<br />
<br />
maybe someone can give me a hint?<br />
<br />
<a href="http://codepad.org/i2gkHbZF"  rel="nofollow">http://codepad.org/i2gkHbZF</a><br />
<br />
thanks for your help :)]]></description>
            <dc:creator>Stefan König</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Thu, 23 May 2013 22:03:24 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,585758,585758#msg-585758</guid>
            <title>Using a primary key as account number (1 reply)</title>
            <link>http://forums.mysql.com/read.php?125,585758,585758#msg-585758</link>
            <description><![CDATA[ Hello all, we are building a large application on MYSQl and I have a db design question. This app will house accounts. Is it a no no to use the account table's auto incrementing primary key as the account number?]]></description>
            <dc:creator>Mark Stopkey</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Wed, 08 May 2013 17:46:53 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,584637,584637#msg-584637</guid>
            <title>slow mysql database (1 reply)</title>
            <link>http://forums.mysql.com/read.php?125,584637,584637#msg-584637</link>
            <description><![CDATA[ Hi,<br />
i have a data base wich will have 500000 lines.<br />
At the moment it have 190000 lines and it's so very slow...<br />
Here is the structure:<br />
CREATE TABLE `produkte` (<br />
  `nummer` int(11) NOT NULL AUTO_INCREMENT,<br />
  `anbieter` text NOT NULL,<br />
  `ueberschrift` text NOT NULL,<br />
  `beschreibung` text NOT NULL,<br />
  `bildlink` text NOT NULL,<br />
  `shoplink` text NOT NULL,<br />
  `preis` float NOT NULL,<br />
  `marke` text NOT NULL,<br />
  `kat1` text NOT NULL,<br />
  `kat2` text NOT NULL,<br />
  `kat3` text NOT NULL,<br />
  `kat4` text NOT NULL,<br />
  PRIMARY KEY (`nummer`)<br />
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=193560 ;<br />
<br />
I have to search the kat elements. So i made the following PHP order:<br />
<br />
$sql=&quot;SELECT distinct kat4 FROM produkte WHERE kat1='&quot;.$_SESSION['kat1'].&quot;' AND kat2='&quot;.$_SESSION['kat2'].&quot;' AND kat3='&quot;.$_SESSION['kat3'].&quot;'&quot;;<br />
$res=mysql_query($sql) or die(mysql_error());<br />
if(mysql_num_rows($res)!=0){<br />
 $sql=&quot;SELECT distinct kat4 FROM produkte WHERE kat1='&quot;.$_SESSION['kat1'].&quot;' AND kat2='&quot;.$_SESSION['kat2'].&quot;' AND kat3='&quot;.$_SESSION['kat3'].&quot;'&quot;;<br />
 $res=mysql_query($sql) or die(mysql_error());<br />
... <br />
And here i fill the option element in a while loop.<br />
<br />
This i make for 4 select elements. <br />
So the script needs more than 12 seconds. It's to slow. <br />
How can i make it's faster?<br />
<br />
Thanx for help.<br />
<br />
Best regards.<br />
Torsten]]></description>
            <dc:creator>Torsten Mueller</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Tue, 23 Apr 2013 16:15:11 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,584620,584620#msg-584620</guid>
            <title>How do I model the tables for storing data from a multi-select combo box? (1 reply)</title>
            <link>http://forums.mysql.com/read.php?125,584620,584620#msg-584620</link>
            <description><![CDATA[ I have a basic data model question.<br />
<br />
What is the most common/recommended way to store the values from a multi-select combo box? Is it best to normalize and create a seperate child table for storing multiple values or is it better to create a column in the same table and store value like a some comma delimited list or using XML elements?<br />
<br />
What are the pros and cons of either approaches from the perspective of &quot;searching&quot; for relavant data.<br />
<br />
I have a related question as well. Say, we have a large # of features that we want to store for a given product/service. Is it better to store the data in the form of an XML in a table column and if so how easy is it to use xml related functions with mysql to be able to retrieve data quickly.<br />
<br />
Any help is greatly appreciated.<br />
<br />
Thanks,<br />
Srini]]></description>
            <dc:creator>Srini Devara</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Tue, 23 Apr 2013 05:57:38 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,583462,583462#msg-583462</guid>
            <title>Table structure for multiple names (2 replies)</title>
            <link>http://forums.mysql.com/read.php?125,583462,583462#msg-583462</link>
            <description><![CDATA[ I'm creating a database that will contain information about artists. like this:<br />
<br />
artists<br />
    • id<br />
    • year_born<br />
    • month_born<br />
    • day_born<br />
    • city_born<br />
    • country_born<br />
    • year_died<br />
    • month_died<br />
    • day_died<br />
    • city_died<br />
    • country_died<br />
    • contemporary<br />
    • unknown<br />
    • views<br />
    • publish<br />
    • time_created<br />
    • time_modified<br />
<br />
Who can have multiple first names, surnames and aliases. The question is whether I should create separate tables for first name, last name and alias. like this:<br />
<br />
artist_surname<br />
    • id<br />
    • artist_id<br />
    • name<br />
    • sorting<br />
    • publish<br />
    • time_created<br />
    • time_modified<br />
<br />
artist_forename<br />
    • id<br />
    • artist_id<br />
    • name<br />
    • sorting<br />
    • publish<br />
    • time_created<br />
    • time_modified<br />
<br />
artist_alias<br />
    • id<br />
    • artist_id<br />
    • name<br />
    • sorting<br />
    • publish<br />
    • time_created<br />
    • time_modified<br />
<br />
Or if I should have it all in one table and there determine what type it is. like this:<br />
<br />
artist_name<br />
    • id<br />
    • artist_id<br />
    • name<br />
    • name_type (surname, forename, alias)<br />
    • sorting<br />
    • publish<br />
    • time_created<br />
    • time_modified<br />
<br />
Would really appreciate if the experts could give their opinion!]]></description>
            <dc:creator>J. Holmberg</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Wed, 10 Apr 2013 03:58:57 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,583056,583056#msg-583056</guid>
            <title>Process Colission Issues on production tables (1 reply)</title>
            <link>http://forums.mysql.com/read.php?125,583056,583056#msg-583056</link>
            <description><![CDATA[ With the risk of sounding like a complete newbie I thought best to first check this with the forum to find out by others experience if my consideration is simply unfounded or not.<br />
<br />
While running a set of fairly large insert queries I keep tabs of the process in the MySQL Administrator tool &gt;&gt; Server Connections &gt;&gt; Threads window...<br />
<br />
I just noted that when I use three different process id's simultanously I now happened upon a collision in the process que.<br />
<br />
Example:<br />
<br />
PID 8  --&gt;           INSERT INTO sometable001<br />
PID 9  --&gt;           INSERT INTO sometable002<br />
PID 10 --&gt; locked    INSERT INTO sometable001<br />
<br />
Apparently the PID 8 got there before PID 10 did.<br />
<br />
Now, hypothetically I would run in to this at some point on a production server as well. Greatest risk being while running a lot through PHP with queries which may run up loads of results if range restrictions cannot be imposed properly.<br />
<br />
How would one best go about mitigating this risk occuring on heavy loaded web sites?<br />
<br />
Or is this a non issue by the server (usually a standard well configured LAMP machine) being able to redirect such issues.<br />
<br />
After all, it is quite common a smaller site with less users only having a limited set of user names to access the DB through.]]></description>
            <dc:creator>Mike Jonsson</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Fri, 05 Apr 2013 04:06:11 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,581965,581965#msg-581965</guid>
            <title>Database with people, addresses, companies and telephone numbers (3 replies)</title>
            <link>http://forums.mysql.com/read.php?125,581965,581965#msg-581965</link>
            <description><![CDATA[ Hello Everybody,<br />
<br />
I'm pretty sure this question has been asked several times and it should actually be a textbook question. However I haven't found it anywhere and so, sorry for posting again.<br />
<br />
The problem I'm having is to design a database to store data for people, companies, addresses and telephone numbers.<br />
<br />
Almost all of the relationships would be M:N (a person can work at several companies and a company can have several people working for it, a person can have several addresses and so can a company, whereas at one address can live several people and be located several companies, etc.). The only exception I can come up with is that a telephone number normally is located fisically at only one address, but one address may have more than one telephone numbers (or none, obviously).<br />
<br />
Now, I can come up with two possible solutions:<br />
<br />
1) Make a connection table for each M:N relationship (like Person and Address, where person_id and address_id are the foreign keys in this table and the combination is unique). In this case for the person/address/telephone number relationships I guess I would need all three tables: person_address, person_telephone and address_telephone, otherwise I loose information on which telephone number is at which address of, say, a certain person. Same for the other relationships, or am I missing something?<br />
<br />
2) Make one big table with person_id, address_id, company_id and telephone_id (and maybe some additional information which is not that relevant for my question). This table would not be normalized, it would have some columns set to NULL for some rows and some redundant data. I'm also assuming in this case I would have to create an index on all foreign keys. Probably it would also be better to give it an extra primary key like &quot;person_company_address_telephone_id&quot;.<br />
<br />
The questions are:<br />
<br />
- Is there any other way that I'm not seeing?<br />
<br />
- Which solution is better from a maintenance, data consistency and performance point of view?<br />
<br />
Thank you very much if anyone can shed some light on this (or point to an existing solution).<br />
<br />
Andrea.]]></description>
            <dc:creator>Andrea Croci</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Wed, 03 Apr 2013 23:51:11 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,581062,581062#msg-581062</guid>
            <title>How to update the table on auto-disconnect after a period of inactivity from user? (1 reply)</title>
            <link>http://forums.mysql.com/read.php?125,581062,581062#msg-581062</link>
            <description><![CDATA[ I have a &quot;user&quot; table which has a column &quot;account_logout_time&quot;. If the user clicks on &quot;Logout&quot; link, I know the logic of updating the user table for that user with the logout time. But, say, the user steps out and does not return in time before the user session expires in say 15 minutes. Now, how do I write the logic to update the database table with the logout time for that user.<br />
<br />
Thanks<br />
Srini]]></description>
            <dc:creator>Srini Devara</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Thu, 14 Mar 2013 15:40:02 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,581040,581040#msg-581040</guid>
            <title>How to limit # of users per account (4 replies)</title>
            <link>http://forums.mysql.com/read.php?125,581040,581040#msg-581040</link>
            <description><![CDATA[ I am creating a datamodel for a website that I am building. I need to limit the # of users who can simultaneously login to an account to either 1 or 2 depending on the package the customer chooses.<br />
<br />
How do I datamodel the tables to achieve this functionality?<br />
<br />
<br />
Thanks,<br />
Srini]]></description>
            <dc:creator>Srini Devara</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Fri, 15 Mar 2013 15:14:20 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,580170,580170#msg-580170</guid>
            <title>Car Parts Catalogue Database design (3 replies)</title>
            <link>http://forums.mysql.com/read.php?125,580170,580170#msg-580170</link>
            <description><![CDATA[ Can anyone point me to a good source for database desgin related to a car parts catolgue. I'm having difficulty with a proper layout.]]></description>
            <dc:creator>Des Govender</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Fri, 15 Mar 2013 13:38:51 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,579495,579495#msg-579495</guid>
            <title>Multiple Tables Split By Date (6 replies)</title>
            <link>http://forums.mysql.com/read.php?125,579495,579495#msg-579495</link>
            <description><![CDATA[ Hi Guys,<br />
<br />
I have a question on table structures...<br />
<br />
I have a massive table (60M+ rows) that i want to split up.  This table contains transaction records that are queried quite often.  The table is MyISAM replicated between a couple of different MySQL servers.<br />
<br />
My though is to split the table in to multiple tables based on date, with their table name YYYYMM.  This would be great and keep the tables manageable.<br />
<br />
My question is how to query multiple tables to look for some of the data.  Lets say, the time span for the records is 5 years, I would have 60 tables as they are broken down by month.  One of the columns in all the tables has an account_id, and I want to know how many total records there are so I can show pagination.<br />
<br />
I know I can union all the tables together etc, but my concern is that by unioning everything together to create one big table, whether this will hit the performance problems I am having at present as it will still be one big table.<br />
<br />
Does anyone have any ideas on a good way to do this?  I had though summary tables etc etc, but wanted to see if anyone else has done something similar.<br />
<br />
Thanks in advance!]]></description>
            <dc:creator>Billy Simons</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Tue, 26 Feb 2013 08:26:13 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,579254,579254#msg-579254</guid>
            <title>dynamic querying (1 reply)</title>
            <link>http://forums.mysql.com/read.php?125,579254,579254#msg-579254</link>
            <description><![CDATA[ I have a Table containing product info <br />
<br />
we then use a product_ID as a prefix on other tables in which we collect stocking levels/buying activities etc<br />
<br />
I now need a way of iterating over these abc_ProdType1 tables so that I can extract data for marketing reports etc<br />
<br />
I am thinking along the lines of a function/procedure which should iterate across the list of product_ID (I can get this from a simple select query)<br />
<br />
2nd query needs to construct the select query abc_ProdType1 tables by building the table name dynamically incorporating the product_ID<br />
<br />
The results of this query then get Insert into my mktg_Table<br />
<br />
<br />
Does this sound like a reasonable way of tackling my problem<br />
If so can you give some hints as to how I construct this<br />
<br />
<br />
any help greatly appreciated]]></description>
            <dc:creator>Stefan Maric</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Wed, 20 Feb 2013 23:17:06 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,579026,579026#msg-579026</guid>
            <title>How to store footnotes or comments per field (3 replies)</title>
            <link>http://forums.mysql.com/read.php?125,579026,579026#msg-579026</link>
            <description><![CDATA[ The tables I've designed are usually straightforward, something like this:<br />
<br />
CREATE TABLE  `account_trans` (<br />
  `at_id` int(10) unsigned NOT NULL AUTO_INCREMENT,<br />
  `at_recorded` date DEFAULT NULL,<br />
  `at_description` varchar(65) DEFAULT NULL,<br />
  `at_amount` decimal(22,4) DEFAULT NULL,<br />
  `at_price` decimal(22,4) DEFAULT NULL,  <br />
  PRIMARY KEY (`at_id`)<br />
) ENGINE=InnoDB DEFAULT CHARSET=utf8;<br />
<br />
For a new project, I need a provision to store footnotes or comments on all of these fields; for instance, comments as to how the price was calculated. (The comments will be stored in a separate table.) I was wondering how others might have solved a similar pattern. I had two ideas, neither of which is all that attractive to me:<br />
<br />
1) Add a footnote ID field for each field in the primary table. The problem with this solution is that most of the time, most of the footnote ID fields will be blank or zero, as footnotes will probably be added to only one or two items per record.<br />
<br />
2) Change the primary table to something like a &quot;name-value&quot; table, that is, each field in the example above would become a separate record in the table tied together by a single transaction ID, something like this:<br />
<br />
CREATE TABLE  `account_trans` (<br />
  `at_id` int(10) unsigned NOT NULL AUTO_INCREMENT,<br />
  PRIMARY KEY (`at_id`)<br />
) ENGINE=InnoDB DEFAULT CHARSET=utf8;<br />
<br />
CREATE TABLE  `trans_items` (<br />
  `ti_id` int(10) unsigned NOT NULL AUTO_INCREMENT,<br />
  `ti_at_id` int DEFAULT '0',<br />
  `ti_comment_id` int DEFAULT '0',<br />
  `ti_trans_type` varchar(10) DEFAULT null,/*This is the 'name' field*/<br />
  `ti_trans_value` decimal(22,4) DEFAULT null,/*This is the 'value' field*/<br />
  PRIMARY KEY (`ti_id`)<br />
) ENGINE=InnoDB DEFAULT CHARSET=utf8;<br />
<br />
This solution has a couple of problems, it's less human-readable, requires more effort when summing transactions, and doesn't account for adding footnotes to date and other non-numeric fields. It might have other efficiency problems, too. <br />
<br />
If this problem makes sense, I'd appreciate any feedback and better solutions.<br />
<br />
Thanks.]]></description>
            <dc:creator>Brent Bigler</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Sun, 24 Feb 2013 01:11:12 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,575877,575877#msg-575877</guid>
            <title>DB Model for custom-fields management (2 replies)</title>
            <link>http://forums.mysql.com/read.php?125,575877,575877#msg-575877</link>
            <description><![CDATA[ I'm looking to write a webapp that has a series of configurations. For each configuration, there can be any number of questions that needs to be asked.  What I'm trying to do is create a generic &quot;custom fields&quot; table in a database that will allow the admin of the webapp to add as many custom question fields as needed.  Some configurations will not need any custom question fields, whereas other may have 10 or more custom question fields associated with it.<br />
<br />
In the end, I also need to be able to go through and determine which custom questions meet or fail a certain set of requirements.<br />
<br />
Any ideas on how I could implement something like this?]]></description>
            <dc:creator>Chris Bassett</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Tue, 25 Dec 2012 02:07:31 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,575725,575725#msg-575725</guid>
            <title>Is storing a comma separated list in a database column really that bad? (4 replies)</title>
            <link>http://forums.mysql.com/read.php?125,575725,575725#msg-575725</link>
            <description><![CDATA[ Hi guys, <br />
<br />
Imagine a web form with a set of checkboxes (any or all can be selected). I chose to save them in a comma separated list of values stored in one column of the database table.<br />
<br />
Now, I know that the correct solution would be to create a second table and properly normalize the database. It was quicker to implement the easy solution, and I wanted to have a proof-of-concept of that application quickly and without having to spend too much time on it.<br />
<br />
I thought the saved time and simpler code was worth it in my situation, it this a defensible design choice, or should I have normalized it from the start?<br />
<br />
Some more context, this is a small internal application that essentially replaces an Excel file that was stored on a shared folder. I'm also asking because I'm thinking about cleaning up the programm and make it more maintainable. There are some things in there I'm not entirely happy with, one of them is the topic of this question.]]></description>
            <dc:creator>Vincentas Grinius</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Thu, 14 Feb 2013 03:44:34 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,575524,575524#msg-575524</guid>
            <title>Revisited: Working with a billion rows (3 replies)</title>
            <link>http://forums.mysql.com/read.php?125,575524,575524#msg-575524</link>
            <description><![CDATA[ I had posted a question back in August, but somehow I didn't see the reply and I got sidetracked from the project.  I'd like to solicit some input once again.  The original thread is <a href="http://forums.mysql.com/read.php?125,564514"  rel="nofollow">http://forums.mysql.com/read.php?125,564514</a><br />
<br />
Right now I'm just trying to clean up the data in the tables and I think if I can successfully do that, I'll have a good idea on the performance side when I start using it.  Production queries will be very few - maybe 10 per day - but they'll need to be quick.<br />
<br />
As I try to clean up the tables, my first task is to remove duplicates.  I'll focus on two tables.<br />
<br />
I'm running this in dev on Windows 7 64-bit 8GB RAM, MySQL 5.5.12. The two tables have just one column containing a list of words with a maximum length of 20 characters. Table2 has a bunch of entries that should already be in table1. I need to delete the duplicates from table2. <br />
<br />
So far I've tried the following queries but they all go nowhere - just chugs away and never does anything.<br />
<br />
delete * from table2 where record in (select * from table1 where record like &quot;1%&quot;); <br />
<br />
OR<br />
<br />
delete from table2 using table1 inner join table2 where table1.record=table2.record and table1.record like '1%';<br />
<br />
What can I do with my data to make it work? Any tuning I can do to the server? Indexing?]]></description>
            <dc:creator>Mike Mullins</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Fri, 21 Dec 2012 23:22:26 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,575362,575362#msg-575362</guid>
            <title>Help with partitioning an existing table (5 replies)</title>
            <link>http://forums.mysql.com/read.php?125,575362,575362#msg-575362</link>
            <description><![CDATA[ I am a newbie to mysql db. I have a table that I have partitioned by a datetime field<br />
<pre class="bbcode">
create table status (
        SERVERSERIAL    NUMERIC(16) NOT NULL,
        SERVERNAME      VARCHAR(64) NOT NULL,
        FIRSTOCCURRENCE DATETIME NULL,
        CUSTOMER VARCHAR(64) NULL,
        &lt;..many other fields&gt;
        PRIMARY KEY ( SERVERSERIAL, SERVERNAME,FIRSTOCCURRENCE )
)
PARTITION BY RANGE COLUMNS (FIRSTOCCURRENCE)
(
        PARTITION p2012_3 values less than ('2012-09-30'),
        PARTITION p2012_4 values less than ('2012-12-31'),
        PARTITION p2013_1 values less than ('2013-03-31'),
        PARTITION p2013_2 values less than ('2013-06-30'),
        PARTITION p2013_3 values less than ('2013-09-30'),
        PARTITION p2013_4 values less than ('2013-12-31'),
        PARTITION p2014_1 values less than ('2014-03-31'),
        PARTITION p2014_2 values less than ('2014-06-30'),
        PARTITION p2014_3 values less than ('2014-09-30')
)</pre>
<br />
The table currently has 3Mil rows. I want to partition it further by customer since most of my queries also have customer name in the where clause. Have a few questions<br />
<br />
a. I think I need to add the Customer field to the primary key. If so, do I need to suspend all writes to the database when I run the alter command?<br />
b. can someone help with the alter statement for adding customer to partitioning in addition to FIRSTOCCURRENCE or some pointers?<br />
<br />
Thanks<br />
Ravi]]></description>
            <dc:creator>Ravi Malghan</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Sun, 06 Jan 2013 00:25:34 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,570900,570900#msg-570900</guid>
            <title>Best Practice For Database table design (2 replies)</title>
            <link>http://forums.mysql.com/read.php?125,570900,570900#msg-570900</link>
            <description><![CDATA[ Although I have been designing databases for quite some time. I would not consider myself an expert. I have always wondered which is a better practice, for the idea below:<br />
<br />
Lets say that we have a database, with several tables. Some of these tables have a foreign key to a table which stores a status_code.  The catch is, that while some tables may use the same status codes, other tables may use additional status codes. IE: Pending, Approved, (Suspended, hidden, delete)<br />
<br />
Practice #1:<br />
So the question is, would it be better to create multiple tables for status_codes, like such:<br />
<br />
/* Members Status Codes */<br />
CREATE TABLE `Members_Status_Codes` (<br />
  `ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,<br />
  `Name` VARCHAR(30) NOT NULL, <br />
  `Description` VARCHAR(255) NOT NULL, <br />
  PRIMARY KEY(`ID`)<br />
);<br />
<br />
INSERT INTO `Members_Status_Codes` ( `ID`, `Name`, `Description` ) VALUES<br />
( 1, 'Pending', 'This member is pending email verification.' ), <br />
( 2, 'Active', 'This member has completed email verification.');<br />
<br />
/* Blog Status Codes */<br />
CREATE TABLE `Blog_Status_Codes` (<br />
  `ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,<br />
  `Name` VARCHAR(30) NOT NULL, <br />
  `Description` VARCHAR(255) NOT NULL, <br />
  PRIMARY KEY(`ID`)<br />
);<br />
<br />
INSERT INTO `Blog_Status_Codes` ( `ID`, `Name`, `Description` ) VALUES <br />
(1, 'Pending Admin Approval', 'This blog is pending admin approval' ), <br />
(2, 'Approved', 'This blog has been approved for display' ), <br />
(3, 'Hidden By Member', 'This blog has been hidden by the member' );<br />
<br />
/* Advertisement status codes  */<br />
CREATE TABLE `Ad_Status_Codes` (<br />
  `ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,<br />
  `Name` VARCHAR(30) NOT NULL, <br />
  `Description` VARCHAR(255) NOT NULL, <br />
  PRIMARY KEY(`ID`)<br />
);<br />
<br />
INSERT INTO `Ad_Status_Codes` ( `ID`, `Name`, `Description` ) VALUES <br />
(1, 'Inactive', 'This ad is currently inactive.' ), <br />
(2, 'Active', 'This ad is currently active.' ), <br />
(3, 'Expired', 'This ad has expired.' );<br />
<br />
<br />
--------------------  OR  --------------------<br />
Practice #2:<br />
Would it be a better practice to create one table to store all status codes and add an additional column which determines which status code belongs to which table.  Like this:<br />
<br />
/* Status code types table */<br />
CREATE TABLE `Status_Code_Types` (<br />
  `ID` INT UNSIGNED NOT NULL AUTO_INCREMENT, <br />
  `Name` VARCHAR(30) NOT NULL, <br />
  `Description` VARCHAR(255) NOT NULL,<br />
  PRIMARY KEY(`ID`)<br />
);<br />
<br />
INSERT INTO `Status_Code_Types` ( `ID`, `Name`, `Description` ) VALUES <br />
( 1, 'Members', 'These status codes are used by the members table.' ), <br />
( 2, 'Blogs', 'These status codes are used by the blogs table.' ), <br />
( 3, 'Ads', 'These status codes are used by the ads table.' );<br />
<br />
/* Status codes table */<br />
CREATE TABLE `Status_Codes` (<br />
  `ID` INT UNSIGNED NOT NULL AUTO_INCREMENT,<br />
  `Name` VARCHAR(30) NOT NULL, <br />
  `Description` VARCHAR(255) NOT NULL, <br />
  `Type_ID` INT UNSIGNED NOT NULL, <br />
  PRIMARY KEY(`ID`), <br />
  FOREIGN KEY(`Type_ID`) REFERENCES `Status_Code_Types`(`ID`) <br />
);<br />
<br />
INSERT INTO `Status_Codes` ( `ID`, `Name`, `Description`, `Type_ID` ) VALUES <br />
( 1, 'Pending', 'This member is pending email verification.', 1 ), <br />
( 2, 'Active', 'This member has completed email verification.', 1 ), <br />
( 3, 'Pending Admin Approval', 'This blog is pending admin approval', 2 ), <br />
( 4, 'Approved', 'This blog has been approved for display', 2 ), <br />
( 5, 'Hidden By Member', 'This blog has been hidden by the member', 2 ),<br />
( 6, 'Inactive', 'This ad is currently inactive.', 3 ), <br />
( 7, 'Active', 'This ad is currently active.', 3 ), <br />
( 8, 'Expired', 'This ad has expired.', 3 );<br />
<br />
And then in the business logic, add code which queries only status codes for members, for blogs, for ads, etc?<br />
<br />
Now in the above examples, im sure it may not make a bit of difference. Considering there are only 3 tables in the above examples.  But lets say that there were 10, 20 or 30 tables? The first option would add 10, 20 or 30 tables which contain status codes.  The second option would add many more records to one table.<br />
<br />
Any suggestions would be greatly appriciated,<br />
Tim McCune]]></description>
            <dc:creator>Tim McCune</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Sat, 15 Dec 2012 11:32:28 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,570433,570433#msg-570433</guid>
            <title>db design for production selection process (no replies)</title>
            <link>http://forums.mysql.com/read.php?125,570433,570433#msg-570433</link>
            <description><![CDATA[ Need some advice here...<br />
<br />
Trying to create a production selection system using PHP and MySQL (for the web, of course) where a person can specify what type of equipment they have (in this case, farming planter equipment) and our &quot;selection wizard&quot; can come up with a product that suits their needs based on the criteria they have specified.<br />
<br />
I'm thinking this sort of needs to be a pivot table of some kind, where the wizard will &quot;drill down&quot; to one solution using the criteria.<br />
<br />
Right now, I was thinking a series of fields (one field for each possible condition) in a table, and then use a query that finds a row in the table that maches the most number of fields in the query.<br />
<br />
Any suggestions on how to do something like this?  Examples??]]></description>
            <dc:creator>Chris Bassett</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Mon, 08 Oct 2012 15:24:42 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,567308,567308#msg-567308</guid>
            <title>How to retrieve this data as a single row with three new columns (1 reply)</title>
            <link>http://forums.mysql.com/read.php?125,567308,567308#msg-567308</link>
            <description><![CDATA[ I have the following tables:<br />
<br />
user {user_id, name}<br />
family {child_id, mother_id, father_id, address, household_income}<br />
<br />
I want to select a row in family given child_id, mother_id and father_id and have it return all the columns in family along with the 3 new columns for the names of the users associated with child_id, mother_id and father_id<br />
<br />
family {child_id, mother_id, father_id, address, household_income, child_name, mother_name, father_name}<br />
<br />
Is this possible?<br />
<br />
Thanks]]></description>
            <dc:creator>V Ra</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Sat, 08 Sep 2012 04:34:26 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,565478,565478#msg-565478</guid>
            <title>Table design issue and complex query questions (5 replies)</title>
            <link>http://forums.mysql.com/read.php?125,565478,565478#msg-565478</link>
            <description><![CDATA[ Hi All,<br />
<br />
Please could anyone advise about the following table design and resulting select query.  I am getting a partial Cartesian because the joins are not quite right.  These are the tables involved with the relevant indexes and the query follows:<br />
<br />
CREATE TABLE IF NOT EXISTS `NewpersistentCentreProfile` (<br />
  `pmcp_id` int(11) NOT NULL AUTO_INCREMENT,<br />
  `CNA_ID` int(11) NOT NULL,<br />
  `YearMonth` date NOT NULL,<br />
  `ProfileActive` tinyint(1) NOT NULL DEFAULT '1',<br />
  `NetworkTypeID` tinyint(3) NOT NULL,<br />
  `CourseID` tinyint(3) NOT NULL,<br />
  `ProfileEffectiveFrom` date DEFAULT NULL,<br />
  `ProfileEffectiveTo` date DEFAULT NULL,<br />
  `RegsTarget` smallint(5) NOT NULL DEFAULT '0',<br />
  `ComplsTarget` smallint(5) NOT NULL DEFAULT '0',<br />
  `OGSAccessTarget` smallint(5) NOT NULL DEFAULT '0',<br />
  UNIQUE KEY `pmcp_id` (`pmcp_id`),<br />
  UNIQUE KEY `CNA_ID` (`CNA_ID`,`YearMonth`,`ProfileActive`,`NetworkTypeID`,`CourseID`,`ProfileEffectiveFrom`),<br />
  UNIQUE KEY `CNA_ID_2` (`CNA_ID`,`ProfileEffectiveFrom`,`ProfileEffectiveTo`)<br />
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;<br />
<br />
CREATE TABLE IF NOT EXISTS `persistentNetworkType` (<br />
  `NetworkTypeID` tinyint(2) NOT NULL,<br />
  `NetworkTypeDesc` varchar(50) NOT NULL,<br />
  `NetworkType` varchar(5) NOT NULL,<br />
  PRIMARY KEY (`NetworkTypeID`),<br />
  UNIQUE KEY `NetworkCode` (`NetworkType`)<br />
) ENGINE=MyISAM DEFAULT CHARSET=latin1;<br />
<br />
CREATE TABLE IF NOT EXISTS `centresDataByDay` (<br />
  `CNA_ID` int(11) NOT NULL,<br />
  `dateReference` date NOT NULL,<br />
  `myguideRegistrationCount` int(11) NOT NULL DEFAULT '0',<br />
  `goOnRegistrationCount` int(11) NOT NULL DEFAULT '0',<br />
  `myguideRegsYTD` int(11) NOT NULL DEFAULT '0',<br />
  `goOnRegsYTD` int(11) NOT NULL DEFAULT '0',<br />
  `myguideOLBStartsCount` int(11) NOT NULL DEFAULT '0',<br />
  `goOnOLBStartsCount` int(11) NOT NULL DEFAULT '0',<br />
  `myguideOLBStartsYTD` int(11) NOT NULL DEFAULT '0',<br />
  `goOnOLBStartsYTD` int(11) NOT NULL DEFAULT '0',<br />
  `myguideFundableOLBComplsCount` int(11) NOT NULL DEFAULT '0',<br />
  `goOnFundableOLBComplsCount` int(11) NOT NULL DEFAULT '0',<br />
  `myguideOLBCourseComplsCount` int(11) NOT NULL DEFAULT '0',<br />
  `goOnOLBCourseComplsCount` int(11) NOT NULL DEFAULT '0',<br />
  `myguideFundableOLBComplsYTD` int(11) NOT NULL DEFAULT '0',<br />
  `goOnFundableOLBComplsYTD` int(11) NOT NULL DEFAULT '0',<br />
  `myguideOLBCourseComplsYTD` int(11) NOT NULL DEFAULT '0',<br />
  `goOnOLBCourseComplsYTD` int(11) NOT NULL DEFAULT '0',<br />
  `goOnOLBLADCount` int(11) NOT NULL DEFAULT '0',<br />
  UNIQUE KEY `CNA_ID` (`CNA_ID`,`dateReference`),<br />
  KEY `dateReference` (`dateReference`)<br />
) ENGINE=MyISAM DEFAULT CHARSET=latin1;<br />
<br />
CREATE TABLE IF NOT EXISTS `currentCentreFunding` (<br />
  `ccf_id` int(11) NOT NULL AUTO_INCREMENT,<br />
  `pcf_id` int(11) NOT NULL DEFAULT '0',<br />
  `CNA_ID` int(11) NOT NULL,<br />
  `parentCentreRef` int(11) NOT NULL DEFAULT '0',<br />
  `NetworkTypeID` tinyint(2) NOT NULL DEFAULT '0',<br />
  `FundingStateID` tinyint(1) NOT NULL DEFAULT '0',<br />
  `startDatetime` datetime DEFAULT NULL,<br />
  `endDatetime` datetime DEFAULT NULL,<br />
  `profile` smallint(3) NOT NULL DEFAULT '0',<br />
  `dirty` tinyint(1) DEFAULT '0',<br />
  UNIQUE KEY `ccf_id` (`ccf_id`),<br />
  UNIQUE KEY `CNA_ID_2` (`CNA_ID`),<br />
  UNIQUE KEY `CNA_ID` (`CNA_ID`,`startDatetime`)<br />
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;<br />
<br />
CREATE TABLE IF NOT EXISTS `hh_Centre` (<br />
  `CentreID` int(11) NOT NULL AUTO_INCREMENT,<br />
  `CentreCode` varchar(15) DEFAULT NULL,<br />
  `CentreName` varchar(255) NOT NULL,<br />
  `PartnerType` enum('Centre Partner','Access Point') DEFAULT 'Centre Partner' COMMENT 'What type of centre is this?',<br />
  `OrgTypeID` mediumint(5) DEFAULT NULL,<br />
  `LocationID` int(11) NOT NULL,<br />
  `Website` varchar(200) DEFAULT NULL,<br />
  `OpenToPublic` tinyint(1) NOT NULL,<br />
  `WhyNotOpen` varchar(255) DEFAULT NULL,<br />
  `CentreActive` tinyint(1) NOT NULL,<br />
  `MembershipCentre` tinyint(1) NOT NULL,<br />
  `CentreFundingTypeID` smallint(6) NOT NULL DEFAULT '0',<br />
  `CreatedBy` varchar(50) NOT NULL,<br />
  `CreatedDate` datetime NOT NULL,<br />
  `UpdatedBy` varchar(50) DEFAULT NULL,<br />
  `UpdatedDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,<br />
  `DataSource` varchar(50) DEFAULT NULL COMMENT 'Where did we get this data from?',<br />
  `DeliverMaths3To2` tinyint(1) DEFAULT NULL,<br />
  `DeliverEnglish3To2` tinyint(1) DEFAULT NULL,<br />
  `ReceiptSFA1213` tinyint(1) DEFAULT NULL,<br />
  `SFAActivities` varchar(500) DEFAULT NULL,<br />
  `OtherFunding1213` varchar(500) DEFAULT NULL,<br />
  `AwardingBodyStatus1213` varchar(500) DEFAULT NULL,<br />
  `Partnerships` varchar(500) DEFAULT NULL,<br />
  `provideAltContact` tinyint(1) DEFAULT NULL,<br />
  `AltContactTitle` varchar(9) DEFAULT NULL,<br />
  `AltContactFirstName` varchar(100) DEFAULT NULL,<br />
  `AltContactLastName` varchar(100) DEFAULT NULL,<br />
  `AltContactJobTitle` varchar(100) DEFAULT NULL,<br />
  `AltContactEmail` varchar(100) DEFAULT NULL,<br />
  `AltContactPhone` varchar(12) DEFAULT NULL,<br />
  `doesCloseAtLunch` tinyint(1) DEFAULT NULL,<br />
  `lunchClosingTime` varchar(16) DEFAULT NULL,<br />
  `PartnershipsInfo` text,<br />
  PRIMARY KEY (`CentreID`),<br />
  KEY `PartnerType` (`PartnerType`)<br />
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;<br />
<br />
And this is my query that is built dynamically in Joomla:<br />
<br />
SELECT SQL_CALC_FOUND_ROWS <br />
                 &quot;---&quot; AS CentreName, <br />
                  NetworkType, <br />
                  FundingStateID, <br />
                  SUM(RegsTarget) AS RegsProfile,<br />
                  SUM(goOnRegistrationCount) AS goonRegs,<br />
                  SUM(goOnOLBStartsCount) AS goonStarts,<br />
                  SUM(ComplsTarget) AS ComplsProfile, <br />
                  SUM(goOnOLBLADCount) AS goonComps, <br />
                  DATE_FORMAT(dateReference, &quot;%Y-%m&quot;) AS dateReference, <br />
                   &quot;---&quot; AS CNA_ID <br />
FROM  ukon_dw3.persistentNetworkType AS nt,<br />
             uko_2.hh_Centre AS c,<br />
             ukon_dw2.currentCentreFunding AS cf,<br />
             ukon_dw2.centresDataByDay AS cd <br />
             LEFT OUTER JOIN <br />
             ukon_dw3.NewpersistentCentreProfile AS p<br />
             ON cd.CNA_ID = p.CNA_ID AND<br />
                    cd.dateReference BETWEEN p.ProfileEffectiveFrom AND <br />
                                                                         p.ProfileEffectiveTo<br />
WHERE cd.dateReference &gt;= &quot;2012-07-01&quot; AND<br />
               cd.dateReference &lt;= &quot;2012-08-17 23:59:59&quot; AND<br />
               cf.NetworkTypeID IN (3) AND<br />
               cf.CNA_ID = cd.CNA_ID AND <br />
               cf.NetworkTypeID = nt.NetworkTypeID AND <br />
               c.CentreID = cf.CNA_ID AND<br />
               DATE_FORMAT(p.YearMonth,'%Y-%m') BETWEEN<br />
                     DATE_FORMAT('2012-07-01 00:00:00','%Y-%m') AND<br />
                     DATE_FORMAT('2012-08-16 23:59:59', '%Y-%m') AND<br />
              p.ProfileActive = 1 AND<br />
              p.CourseID IN (1)<br />
         <br />
GROUP BY DATE_FORMAT(dateReference, &quot;%Y-%m&quot;),<br />
                     NetworkType, <br />
                     FundingStateID<br />
<br />
1). I am struggling to define the tables and resultant joins between the <br />
cf and cd tables.  The cd table possesses a compound key that hold the date i.e 365 record for each centre.  The cf table doesn't possess a daily date only a centre (CNA_ID) and startDatetime colum.  Hence I can't get a good join. <br />
<br />
2).<br />
<br />
I am also struggling to define the cd and and p joins<br />
<br />
         ukon_dw2.centresDataByDay AS cd <br />
             LEFT OUTER JOIN <br />
             ukon_dw3.NewpersistentCentreProfile AS p<br />
             ON cd.CNA_ID = p.CNA_ID AND<br />
                    cd.dateReference BETWEEN p.ProfileEffectiveFrom AND <br />
                                                              p.ProfileEffectiveTo plus ancillary p cols against constants in the where clause.  The cd table hold 365 record for each centre but the profile table is by month.  I have added the effectivefrom and effectiveto column to try to address the cartesian like problem.<br />
I have added a number of unique keys to the p table because I am trying to cater for future scalability such as the introduction of profiles for multiple courses at a particular centre.<br />
<br />
Many thanks for your help.<br />
<br />
Dave]]></description>
            <dc:creator>David Usherwood</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Tue, 21 Aug 2012 15:05:55 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,564514,564514#msg-564514</guid>
            <title>Working with a billion rows (1 reply)</title>
            <link>http://forums.mysql.com/read.php?125,564514,564514#msg-564514</link>
            <description><![CDATA[ My goal is to use a MySQL database to prevent users from using a password that exists in a password dictionary.  The dictionary that I want to use has about a billion entries.  Getting the data in is one obstacle, but the most important is efficient searching.<br />
<br />
1.  Is this feasible?<br />
2.  What are my options for table design?  One table, multiple?<br />
3.  What's the best way to get the data in?<br />
4.  How can I optimize search?<br />
<br />
I've used MySQL peretty heavily for basic data sets.  This is my first foray into the world of large databases.  My frontend will be PHP.  I can use whatever (free) MySQL version that is recommended but I'm not inclined to switch to a different SQL.<br />
<br />
Thanks for any tips.]]></description>
            <dc:creator>Mike Mullins</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Fri, 10 Aug 2012 08:01:54 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,564469,564469#msg-564469</guid>
            <title>A design quiz (4 replies)</title>
            <link>http://forums.mysql.com/read.php?125,564469,564469#msg-564469</link>
            <description><![CDATA[ Dear all,<br />
<br />
&quot;Company A have large data and needs quick realtime monitoring also. Normally two to three milions of records are inserted into database per day. A realtime monitoring is also needed over the latest incoming data. The historical data must be stored in a way suitable for future analysis and business applications.&quot;<br />
<br />
Which DW model would you suggest?<br />
<br />
- Dimensional Model,<br />
- Corporate Information Factory,<br />
- Data Vault, <br />
- OLAP Cubes,<br />
<br />
or what combinations of above items?<br />
<br />
Yours sincerely,<br />
Vincent]]></description>
            <dc:creator>Vincent R&amp;D</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Tue, 21 Aug 2012 05:22:18 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,564228,564228#msg-564228</guid>
            <title>Business Intelligence + mysql (5 replies)</title>
            <link>http://forums.mysql.com/read.php?125,564228,564228#msg-564228</link>
            <description><![CDATA[ Dear all,<br />
<br />
We are in development phase of a network monitoring system. As a demanding feature we are going to equip our solution with business intelligence.<br />
<br />
As a person who is not aquainted with BI too much, I would like to know more about the requirements of a successful BI with regard to db scheme design.  We already designed our mysql scheme almost close to OLTP standards, but I want to know what makes my database ERD scheme correctly useful for a BI implementation.<br />
<br />
We have not yet decided about the tool we are going to use for BI, so I would be pleased if you give me some clues about available products.<br />
<br />
Best regards,<br />
Vincent]]></description>
            <dc:creator>Vincent R&amp;D</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Sun, 19 Aug 2012 20:50:50 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,563827,563827#msg-563827</guid>
            <title>Formin sql query + Android (1 reply)</title>
            <link>http://forums.mysql.com/read.php?125,563827,563827#msg-563827</link>
            <description><![CDATA[ Hi,<br />
In my android app, I am getting a list of nearby restaurants from Google Place API.<br />
<br />
But unfortunately, this list does not give menus of the restaurant.<br />
<br />
I have T_RESTAURANT and T_MENU tables.<br />
<br />
Lets say, I get 4 restaurants in the list returned by API, then how should I make my query to extract data.<br />
<br />
If I do:<br />
select name, votes, review from T_MENU where restaurant_name = REST_NAME_1;<br />
and I have to fire this query for each of the restaurants i.e. 4 times in this case.<br />
<br />
Can anyone suggest me a good solution?<br />
<br />
Thanks.]]></description>
            <dc:creator>chanchal kumari</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Sat, 04 Aug 2012 04:52:13 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,563668,563668#msg-563668</guid>
            <title>please check my db design (no replies)</title>
            <link>http://forums.mysql.com/read.php?125,563668,563668#msg-563668</link>
            <description><![CDATA[ wrong thead, sorry]]></description>
            <dc:creator>Moisha Moska</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Thu, 02 Aug 2012 07:28:40 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,563475,563475#msg-563475</guid>
            <title>Optimize this query (1 reply)</title>
            <link>http://forums.mysql.com/read.php?125,563475,563475#msg-563475</link>
            <description><![CDATA[ Dear friends,<br />
i have the following query<br />
<br />
select distinct `loan_trend_ltr`.`ltr_period` AS `ltr_period`,<br />
`loan_trend_ltr`.`bnk_code` AS `bnk_code`,<br />
`contact_ctc`.`ctc_province_code` AS `ctc_province_code`,<br />
`loan_trend_ltr`.`lon_class` AS `lon_class`,<br />
`loan_trend_ltr`.`lon_status` AS `lon_status`,<br />
`loan_trend_ltr`.`branch_id` AS `branch_id`,<br />
`loan_trend_ltr`.`lon_sys_id` AS `lon_sys_id`,<br />
`loan_trend_ltr`.`lon_update_date` AS `lon_update_date` <br />
from (`loan_trend_ltr` <br />
join `contact_ctc` <br />
on(((`loan_trend_ltr`.`bnk_code` = `contact_ctc`.`bnk_code`) <br />
and (`contact_ctc`.`branch_id` = `loan_trend_ltr`.`branch_id`)))) <br />
<br />
where (`contact_ctc`.`ctc_province_code` is not null) <br />
group by `loan_trend_ltr`.`lon_sys_id` having (`loan_trend_ltr`.`lon_status` = _utf8'ACTIVE') <br />
<br />
each table has 100000+ records so it takes so long time running.<br />
<br />
anyone please help me optimize this query]]></description>
            <dc:creator>phouthasone thongmanivong</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Thu, 02 Aug 2012 03:02:38 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,561990,561990#msg-561990</guid>
            <title>schema optimization (2 replies)</title>
            <link>http://forums.mysql.com/read.php?125,561990,561990#msg-561990</link>
            <description><![CDATA[ hi,<br />
<br />
we are using a table event_logs, there are 24 columns in that table, by looking at columns can you say we normalize the table by splitting the columns.<br />
<br />
Most of the queries are slow, We already have indexes for all queries.<br />
<br />
+----------------+------------+------+-----+---------------------+----------------+<br />
| Field          | Type       | Null | Key | Default             | Extra          |<br />
+----------------+------------+------+-----+---------------------+----------------+<br />
| id             | bigint(20) | NO   | PRI | NULL                | auto_increment |<br />
| event_id       | int(11)    | NO   | MUL | NULL                |                |<br />
| session_id     | bigint(20) | NO   |     | NULL                |                |<br />
| param1         | int(11)    | NO   | MUL | NULL                |                |<br />
| param2         | int(11)    | NO   | MUL | NULL                |                |<br />
| param3         | int(11)    | NO   | MUL | NULL                |                |<br />
| param4         | int(11)    | NO   | MUL | NULL                |                |<br />
| param5         | int(11)    | NO   | MUL | NULL                |                |<br />
| param6         | int(11)    | NO   | MUL | NULL                |                |<br />
| param7         | int(11)    | NO   | MUL | NULL                |                |<br />
| param8         | int(11)    | NO   | MUL | NULL                |                |<br />
| lat            | float      | NO   |     | 0                   |                |<br />
| longi          | float      | NO   |     | 0                   |                |<br />
| country_id     | int(11)    | NO   |     | NULL                |                |<br />
| ip             | int(32)    | NO   |     | NULL                |                |<br />
| cdate          | date       | NO   | PRI | NULL                |                |<br />
| ctime          | time       | NO   |     | NULL                |                |<br />
| cts            | timestamp  | NO   |     | 0000-00-00 00:00:00 |                |<br />
| os_version     | int(11)    | NO   |     | NULL                |                |<br />
| app_version    | int(11)    | NO   |     | NULL                |                |<br />
| device_version | int(11)    | NO   |     | NULL                |                |<br />
| udid           | int(11)    | NO   |     | NULL                |                |<br />
| jail_broken    | tinyint(4) | NO   |     | 0                   |                |<br />
| jail_broken2   | tinyint(4) | NO   |     | 0                   |                |<br />
+----------------+------------+------+-----+---------------------+----------------<br />
<br />
I would like to move lat,longi,ip,os_version,app_version,device_version itto another table. <br />
<br />
Is it correct one to do to make the query easier. <br />
<br />
The table contains 4 crore records.]]></description>
            <dc:creator>dileep ch</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Mon, 23 Jul 2012 18:56:53 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,560752,560752#msg-560752</guid>
            <title>Calculated &quot;virtual&quot; rows (7 replies)</title>
            <link>http://forums.mysql.com/read.php?125,560752,560752#msg-560752</link>
            <description><![CDATA[ I'm new to these forums, so please forgive me if I chose the wrong forum for this post.<br />
<br />
I'm currently planning the implementation of some kind of BI system. While creating the DB design, I encountered a problem for which I hope to get hints to solve it on these forums.<br />
The system I'm designing should store a set of business figures for a set of years and locations. My core problem is that some of the figures are not directly stored in the database but have to be calculated from other figures.<br />
<br />
Please take a look the following example DB:<br />
<br />
<pre class="bbcode">
mysql&gt; select * from dim_location;
+-------------+------------------+---------------------+
| location_id | location_name    | location_address    |
+-------------+------------------+---------------------+
|           1 | Office Munich    | NULL                |
|           2 | Office Stuttgart | Koenigstraße 1      |
|           3 | Office Hamburg   | Reeperbahn 3        |
|           4 | Office Berlin    | Unter den Linden 16 |
+-------------+------------------+---------------------+

mysql&gt; select * from dim_year;
+---------+------------------------+
| year_id | year_comments          |
+---------+------------------------+
|    2009 | NULL                   |
|    2010 | the crisis hit us hard |
|    2011 | NULL                   |
|    2012 | getting better again   |
+---------+------------------------+

mysql&gt; select * from dim_figure;
+---------------------------+----------------------------------------------------+--------------------------------------------------------+
| figure_id                 | figure_description                                 | figure_rule                                            |
+---------------------------+----------------------------------------------------+--------------------------------------------------------+
| admin_costs               | Administrative Costs                               | NULL                                                   |
| admin_costs_purchase_dist | Administrative Costs distribution key for Purchase | NULL                                                   |
| admin_costs_sales_dist    | Administrative Costs distribution key for Sales    | NULL                                                   |
| admin_costs_stock_dist    | Administrative Costs distribution key for Stock    | NULL                                                   |
| goods_costs               | Costs for buying goods                             | NULL                                                   |
| marketing_costs           | Costs for doing marketing                          | NULL                                                   |
| purchase_costs            | Total Purchase Costs                               | goods_costs + admin_costs_purchase_dist * admin_costs  |
| sales_costs               | Total Sales Costs                                  | marketing_costs + admin_costs_sales_dist * admin_costs |
| stock_costs               | Total Stock Costs                                  | warehouse_costs + admin_costs_stock_dist * admin_costs |
| total_costs               | Total Costs                                        | purchase_costs + stock_costs + sales_costs             |
| warehouse_costs           | Costs for maintaining the warehouse                | NULL                                                   |
+---------------------------+----------------------------------------------------+--------------------------------------------------------+

mysql&gt; select * from fact_data;
+---------+-------------+-------------+-------+
| year_id | location_id | figure_id   | value |
+---------+-------------+-------------+-------+
|    2009 |           1 | admin_costs |   300 |
...</pre>
<br />
My current plan is to store all &quot;basic&quot; figures (i.e. figures that don't have a figure_rule) in the fact_data table. On the other hand, all calculated figures should be calculated in some kind of magic view... something like this:<br />
<pre class="bbcode">SELECT year_id, location_id, figure_id, value FROM ###MAGIC### WHERE figure_id IN (&quot;total_costs&quot;, &quot;purchase_costs&quot;, &quot;goods_costs&quot;) AND year_id = 2010;</pre>
<br />
My question boils down to: What do I put in ###MAGIC###? ;-)<br />
And: If something like this is not possible (or not performant for ~200 figures and ~30 locations), what design alternatives would you suggest?<br />
<br />
Just for clarification: I put the figure_rule in the dim_figure table only for demonstration purposes. Of course the figure_rule has to become a part in some query.<br />
I already tried something like this:<br />
<pre class="bbcode">(SELECT * FROM fact_data)
UNION
(SELECT a.year_id, a.location_id, &quot;purchase_costs&quot;, a.value + b.value * c.value 
 FROM fact_data a
 LEFT JOIN fact_data b ON a.year_id = b.year_id AND a.location_id = b.location_id AND b.figure_id = &quot;admin_costs_purchase_dist&quot;
 LEFT JOIN fact_data c ON a.year_id = c.year_id AND a.location_id = c.location_id AND c.figure_id = &quot;admin_costs&quot;
 WHERE a.figure_id = &quot;goods_costs&quot;);</pre>
<br />
However, this is basically the opposite of performant. ;)<br />
<br />
<br />
Thank you for any replies in advance!<br />
<br />
Cheers,<br />
Hauke]]></description>
            <dc:creator>Hauke P.</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Thu, 02 Aug 2012 14:31:34 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?125,560200,560200#msg-560200</guid>
            <title>MySQL Query (2 replies)</title>
            <link>http://forums.mysql.com/read.php?125,560200,560200#msg-560200</link>
            <description><![CDATA[ Any help appreciated - <br />
<br />
I have 3 tables:<br />
<br />
Table 1 (Postcode_Groups) where example rows are:<br />
BS1,BS2,BS3,<br />
BS4,BS5,BS6<br />
etc<br />
<br />
Table 2 (Customers) where example rows are:<br />
customer postcode_district = 'BS2' <br />
customer postcode_district = 'BS3' <br />
customer postcode_district = 'BS7' <br />
<br />
<br />
Table 3 (GolfClub) where example postcode_district of the club = 'BS3'<br />
<br />
I need a select * on customers where golfclub postcode_district = 'BS3'<br />
<br />
Thanks in advance - Vance (Bristol UK)]]></description>
            <dc:creator>Vance Raeburn</dc:creator>
            <category>Database Design and Data Modelling</category>
            <pubDate>Mon, 09 Jul 2012 12:22:14 +0000</pubDate>
        </item>
    </channel>
</rss>
