|
just another regularban.info web blog |
| MEMBERS: | Efficient SQL Databases
Don't be fooled by seeming simplicity. A lot of developers get comfortable with a certain way of designing a database for their web applications that they miss out on techniques they should rather employ to make things run faster and more efficiently. A lot of developers don't bear in mnd that the small site they are creating now might grow into something incredibly large and complex, and the database they designed has become bloated and doesn't scale well to meet the demands of the increased traffic. This article hopes to provide web developers with a few techniques to help make their database and queries faster and more efficient. 1. Avoid Character Types When you are designing a database, it is so easy to set all data types to the VARCHAR type as it can then contain any data you want; numbers or text. But character data is amongst the most inefficient data type you can get. If a field is only going to contain numbers, then make it one of the appropriate types (INT, DOUBLE, etc). Also, wherever possible in your web development code, try to use numeric data types as opposed to characters. One of the most common things a script has to store are flags like whether someone answered yes or no to a question, etc. You could of course store it as 'Y' or 'N' but why not store it as 0 and 1? The reason this makes a difference is when you have a database, for example, with over 500 000 entries, and are running a SELECT on that field, comparisons are processed a lot faster for numeric data types than character types. Also, if you need to return data to the calling script, numeric data is less memory intensive than character data. In addition, your web development language (PHP, ASP, etc) would also be able to process and perform functions on numeric data better than character data. I am not trying to convince you never to use character data types. Sometimes it is a necessity, but if you can find ways to reduce the amount of character data processed by your SQL database, the better your server will cope. 2. Normalization Normalizing a database is really quite a complex process. It is a process that describes a way to design a database structure to avoid repetition of data in your database and can lead to significant performance benefits if employed correctly. However, the entire process of normalisation is a bit beyond the scope of this article as it can fill books on its own, but any developer designing a database should seriously consider becoming knowledgable about normalisation and employing it in their own designs. For a good tutorial on this process: http://www.keithjbrown.co.uk/vworks/mysql/mysql_p7.php 3. DateTime vs Timestamp fields This actually relates to 1. a bit. The big difference to bear in mind here is that a field of type DATETIME is actually stored as a series of characters. A field of type TIMESTAMP is actually stored as an integer. So therefore, a more efficient way of storing dates is using the timestamp method. The timestamp has its drawbacks however. For one, you cannot store a date early than 1 January, 1970. Also, timestamps in your script will need recalculating to get to the character format. Because of this recalculation, it may not be better to store as timestamp. It really is a case of testing which format works better for your needs. 4. Use LIMIT where possible In your queries, if you are doing a SELECT to a database and you only expect a certain number of results, using the LIMIT statement can speed your query up incredibly. For example, if you have a table of users and you need to run a query to search for one users record, you can use a query like: SELECT user_name FROM users WHERE user_id = 453; This query is perfectly valid and will return the right result. But you also know there will only be ONE result. The query above will search the database, find what you want, but then still continue searching after that. It would run a lot faster if you could tell the query that once it has found what you are looking for to stop searching. LIMIT can do this, as this query shows: SELECT user_name FROM users WHERE user_id = 453 LIMIT 1; Imagine this scenario. You have a table called logins, that records every login from a user. It currently contains over 2 000 000 records, and you want to find the first time a user logged in. Now bear in mind that because this table inserts data over time, it is already sorted for by date. You could do the following query: SELECT MIN(login_date) FROM logins WHERE user_id = 4876; This will return the record you want, but SQL will now have to get all dates for that user, sort them and then return the lowest value to you. Our table is already date sorted simply because of the way it records data for us. So using LIMIT can be more effective: SELECT login_date FROM logins WHERE user_id = 4876 LIMIT 1; Because it is sorted, the first one will always be a users first login. 5. Avoid using LIKE If you have tried to employ 1. above, then hopefully you will be in a scenario where you do not need to use LIKE all that much. LIKE is one of the most inefficient ways of searching a table. LIKE performs a text comparison search in a field and with no wildcards is as efficient as a direct comparison; i.e. WHERE name = 'Jane' is equivalent to WHERE name LIKE 'Jane'. It is when you start introducing the wildcard characters like '%' that things get really hairy. If you do have to use LIKE, then at least try and make efficient use of the wildcards. These are '_' (underscore) and '%'. Let me explain all this with a real world example. In a project I was involved in, we had a SQL database storing logs generated automatically from a mail server. Unfortunately, the mail server pretty much just dumped a very long string of text data into a field that contained the data we wanted. A script had to be written to find all logs that referred to a login by a user into the POP server. The only way we could do this was to search every record for a string in the msg field that had the text "User logged in" in it. The first query developed was something like this: SELECT msg FROM logs WHERE msg LIKE '%User logged in%'; This query took on average of about 35 minutes to process. Obviously not an ideal situation. The way the LIKE worked here was that it had to parse through every single portion of each and every record in the msg field looking for text that matched "User logged in" anywhere in the text. We were able to determine eventually that the text "User logged in" occured at the end of that text in the msg field and so we altered the query: SELECT msg FROM logs WHERE msg LIKE '%User logged in'; The '%' at the end was removed as we do not want to worry about text after because there is none. The query now only compares text to our string in the msg field at the end of the field and no longer parses through the entire piece of text stored in msg. The query now ran in under 2 minutes. (This was actually still too long, but how we optimised from there is a little beyond the scope of this article.) Hopefully with all these elements put into practice on your next web development project, you can have a database that runs quickly, efficiently, uses as little resources as possible and wont grind to a halt when the load suddenly increases.
Learn How To Design and Build Websites With Dreamweaver
If you are considering building your own website and do not know anything about building or designing websites the fast way to learn is getting involved with a tutorial of some kind. Learn from somebody that already knows how things are done and just follow their examples as you start building your website. There are two way to go, you can find a e-book Dreamweaver course or a Video course where Dreamweaver is explained. Both ways will work it all up to you to find the best way that will help you get started the fastest, I have included a few mistakes that you want to avoid when building your first website with dreamweaver. 1) Splash pages Splash pages are the first pages you see when you arrive at a website, normally with a big image or something like this. These pages does not make much sense when building your site as you always have to keep in mind how does navigation works for my visitors and how does search engines like Google see my page. So if you can avoid it do not make a splash page as your index.htm page. 2) Banner advertisements If you want to make money with your website, then AdSense will make the most sense for your users, banner ads takes up a lot of space and history tells us that people do no click on them. So don't waist your space on banner ads. 3) Clear navigation Navigation on your website is very important for your customers but even more important for your search engine ranking. By making easy 1-click navigation is a must on all pages. If your customers do not know how to navigate your site people will not see what you want them to see. So forget flash and drop down menus 4) Clear indication of where the user is When visitors are deeply engrossed in browsing your site, you will want to make sure they know which part of the site they are in at that moment. That way, they will be able to browse relevant information or navigate to any section of the site easily. Don't confuse your visitors because confusion means "abandon ship"! 5) Avoid using audio on your site People will leave your site if they get loud audio from your site and they have to jump to turn down their speakers so avoid audio on your site. So use the Dreamweaver tutorial to learn website building and saves alot of money by doing it yourself. Even if you don't know HTML or anything about building your own website you can learn it really fast by using an online tutorial.
How to Build Website From Scratch Without HTML Knowledge At All
Internet really is the money-making, cash-spitting, wealth-building profit machine, just like the dreamers said it was. However, not many people realized this huge earnings potential. The biggest problem they faced is just that they do not know how to build website from scratch. And their lack of knowledge about HTML often holds them back to build a successful money-making website. This article is about that, teaching you how to build website from scratch without HTML knowledge at all. Let's get going... List Everything You Know About Anything The best capital in the online world is not about money, but knowledge instead. The good news about making money online is that, you can monetize your knowledge instantly. No matter how useless you think about anything you know, there will always be someone out there that is looking for that information. The best part is that you can get paid by just sharing the information. You can start by listing everything you know about anything. This can be an activity that you love doing during your leisure time, something that you did as a part time job or techniques that you had learnt while working in the office. Divide those subject matters into several topics and rank them from the theme you are most comfortable with. It is a good idea to begin with the top preference first. Research The Most Profitable Keywords Refine your preferred topics by doing some keyword research. You can use the free keyword tools like Overture Keyword Tool to get started or some paid keyword tools like Wordtracker to dig even deeper. After collecting all those possible keywords, continue researching its profitability by looking at the possible affiliate products as well as the cost-per-click (CPC) in the Google AdWords. Moving forward, you will have a list of the most profitable keywords and the "not so profitable" one. Rank them accordingly and start structuring your web design concept. Then, locate the most profitable keywords in the Tier-2 pages; where they are accessible from the homepage, and the rest in the Tier-3 pages. By doing so, web pages with the profitable keywords are able to enjoy maximum exposure. Build Web Pages With WYSIWYG Softwares By now you must already have a concrete web structure. Remember it by heart because you are about to build a website that will make money 24/7. What left is just a great content that will makes your website stands out than the rest. From now on, focus on building great contents and keep on creating them so that the visitors able to keep in touch with you in the long run. However, you need a website builder that able to connect your contents with the visitors into a presentable or user-friendly format. You can start building your profitable website with Site Build It. In fact, it comes with paid keyword research tool, hosting, domain names, auto-responder and marketing tips for free. You don't have to worry about how to build website from scratch without HTML knowledge anymore.
|
* About Archives
Categories:
Last Updated: |
| regularban.info
is proudly powered by WordPress MU running
on regularban.info.
Create a new blog and join in the fun! Entries (RSS) and Comments (RSS). |