Jump to content

fenway

Staff Alumni
  • Posts

    16,168
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by fenway

  1. An IN() clause would have saved you a lot of headaches.
  2. You'd have to benchmark it-- a count is usually faster.
  3. SQL_CALC_FOUND_ROWS can be insanely slow.
  4. If it's just a single sub-category, a single LEFT JOIN should be sufficient.
  5. I don't know what that means.
  6. because the same query is used in many places within the site. That's not a good reason -- do you use connection pooling?
  7. fenway

    MYSQL LIMIT

    Barand just knows everything -- including the power of secret and magic constants.
  8. What does your query output? How deep in your nesting?
  9. No, there isn't -- SPs don't support dynamic SQL. And they're not supposed to. The whole concept is that the server can optimize the query -- but you've just made that impossible -- and that's why it's not supported.
  10. Why it this an SP to begin with/
  11. Well, you could store the binary data in the database -- but IMHO, it's far easier to simply store a relative pathname and store them using the filesystem.
  12. This sounds like homework -- what are you actually trying to do?
  13. fenway

    MYSQL LIMIT

    2^32 - 1 works too -- but I don't think you can use expressions in the LIMIT.
  14. I've heard nothing but horror stories about them.
  15. Covers: Part 1: Using the MySQL Improved Extension, mysqli Part 2: Using the MySQL Extension, mysql Part 3: Using the PDO Extension With MySQL Driver, pdo_mysql Part 4: Using the MySQL Native Driver for PHP, mysqlnd Tutorial is here.
  16. Well, a scalar subquery, that is.
  17. Hopefully this presentation will stay online at scribd... it's simply fantastic, probably the best I've come across in recent memory. At 220 slides, it's quite lengthy -- but the lessons learned are invaluable, so be sure to read all the way to the end. A MUST READ!!!! EDIT: This year's version of the presentation -- some really great stuff in here, particuarly about hierarchies.
  18. At the 2008 MySQL Conference and Expo, The Pythian Group gave away EXPLAIN cheatsheets (PDF).
  19. This resource covers a very broad range of topics... it's worth a look, though, especially if you're stumbling in the early stages of configuration.
  20. Basically, this blog contains a regularly-updated run-down of MySQL functions, with a short description and a few hints on how to use them; RSS feed here.
  21. Please read the excellent FAQ thread on this issue by our very own wildteen88.
  22. To ensure that your post gets answered as soon as possible, please make sure you've included the following: your MySQL server version -- absolutely required! the raw MySQL statement in question [in a CODE block, and without any PHP variables] any errors that MySQL returns to the client [from mysql_error()] the table structure & column indexes of the relevant tables [via SHOW CREATE TABLE is preferred] the EXPLAIN output for your query, if applicable a clear and concise description of what you want this statement to achieve a description of what it's currently doing that's not to your liking a brief listing of the types of things you've attempted so far If you don't provide any or all of the above, don't be surprised if your post never gets the attention it deserves. --fenway
  23. You'll find a very good list of do's and don'ts written by Matt Kruse here -- highly recommended.
  24. MySQL's tech resource article on database normal forms is an excellent read. NEW!!! - A large (160MB, 4M record) sample database with test suite for MySQL -- fantastic for running "real" queries. In addition, MySQL provides a number of sample databases for testing purposes; personally, I find this one to be the most useful for playing around with SQL statements and such. The Zip Code Database Project exists to provide US Zip Codes in their entirety; latitude and longitude coordinates included! The downloads are in CSV and MySQL table dump formats. Also, there's an pretty good online "data generator", and SQL is one of the options... although personally, I prefer the integers table approach (courtesy of Baron Schwartz): set @num_gamers := 10000, @num_countries := 5, @num_games := 10; drop table if exists gamer; drop table if exists game; drop table if exists country; drop table if exists score; drop table if exists semaphore; create table gamer( gamer int not null, country int not null, name varchar(20) not null, primary key(gamer) ); create table game( game int not null, name varchar(20) not null, primary key(game) ); create table score( gamer int not null, game int not null, score int not null, primary key(gamer, game), index(game, score), index(score) ); create table country( country int not null, name varchar(20) not null, primary key(country) ); -- I use the integers table to generate large result sets. drop table if exists integers; create table integers(i int not null primary key); insert into integers(i) values(0),(1),(2),(3),(4),(5),(6),(7),(,(9); insert into country(country, name) select t.i * 10 + u.i, concat('country', t.i * 10 + u.i) from integers as u cross join integers as t where t.i * 10 + u.i < @num_countries; insert into game(game, name) select t.i * 10 + u.i, concat('game', t.i * 10 + u.i) from integers as u cross join integers as t where t.i * 10 + u.i < @num_games; insert into gamer(gamer, name, country) select th.i * 1000 + h.i * 100 + t.i * 10 + u.i, concat('gamer', th.i * 1000 + h.i * 100 + t.i * 10 + u.i), floor(rand() * @num_countries) from integers as u cross join integers as t cross join integers as h cross join integers as th; insert into score(gamer, game, score) select gamer.gamer, game.game, floor(rand() * @num_gamers * 10) from gamer cross join game;
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.