User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 12 Apr 2003, 11:52   #1
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Back to MySQL again...

Ok, I stole someone else's PA dump script and adapted it to mysql and now I'm onto cluster/para ranks. The code I'm using to generate the planetary cluster ranks is...
Code:
$i=1;
while($i <= $cluster){
  $rank = 1;
  $query = 'SELECT x,y,z FROM plandump WHERE tick='.$tick.' 
    AND x='.$i.' ORDER BY size DESC';
  $result=$database->openConnectionWithReturn($query);
  while(list($x, $y, $z) = mysql_fetch_array($result)){
    $query = 'UPDATE plandump SET croidrank='.$rank.' 
      WHERE x='.$x.' AND y='.$y.' AND z='.$z.' AND tick='.$tick;
    $database->openConnectionNoReturn($query);
    $rank++;
  }
  $i++;
}
...but it takes forever and a day. There must be a quicker more efficient way to do it but I can't think of one, any ideas?
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline   Reply With Quote
Unread 12 Apr 2003, 12:03   #2
Mit
Let battle commence
 
Mit's Avatar
 
Join Date: Feb 2002
Location: England
Posts: 732
Mit is a jewel in the roughMit is a jewel in the roughMit is a jewel in the rough
It will take a while, a suggestion, that was actually given to me, was to work in RAM. Save teh entire universe in an array, change stuff and update once per plent instead of 8 times it would have been for me and the official tools. One hell of a lot quicker.

Each planet has an idividual ID, thats how i reference it.
__________________
Mit
http://tim.igoe.me.uk - Development Blog
Whats on TV now - UK TV Guide

<Mendosa> mit is a cute cudlly toy that will be in the shops by christmas
<mig-work> ur now my eternal fav pa god
<Squiz> i name thee, Sir Mit
<Zeus> u my friend are a true gamer I knew u were
Mit is offline   Reply With Quote
Unread 12 Apr 2003, 12:46   #3
Pitchfork
Tourist
 
Join Date: Jun 2001
Location: moon
Posts: 90
Pitchfork is an unknown quantity at this point
Quote:
Originally posted by Mit
It will take a while, a suggestion, that was actually given to me, was to work in RAM. Save teh entire universe in an array, change stuff and update once per plent instead of 8 times it would have been for me and the official tools. One hell of a lot quicker.

Each planet has an idividual ID, thats how i reference it.
That's it, I read the planetfile into memory, then do a few qsorts, then use postgresql's COPY FROM stdin function (similar to mysql's read data infile or sumthing), pretty fast
__________________
Quote:
Originally posted by Bloomers III
sex is dirty and for losers who can't masturbate properly
Pitchfork is offline   Reply With Quote
Unread 12 Apr 2003, 12:49   #4
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Quote:
Originally posted by Pitchfork
That's it, I read the planetfile into memory, then do a few qsorts, then use postgresql's COPY FROM stdin function (similar to mysql's read data infile or sumthing), pretty fast
My bash scripting sucks in a real big way otherwise I'd do it like that

The initial dump handling is done using LOAD DATA INFILE and it's almost instantaneous but I'm having to use PHP to do the rank processing and it's slooooow
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline   Reply With Quote
Unread 12 Apr 2003, 12:57   #5
Pitchfork
Tourist
 
Join Date: Jun 2001
Location: moon
Posts: 90
Pitchfork is an unknown quantity at this point
Quote:
Write in C
(to the tune of the Beatles' "Let it Be")

When I find my code in tons of trouble,
Friends and colleagues come to me,
Speaking words of wisdom:
"Write in C."

As the deadline fast approaches,
And bugs are all that I can see,
Somewhere, someone whispers:
"Write in C."

Write in C, Write in C,
Write in C, oh, Write in C.
LOGO's dead and buried,
Write in C.

I used to write a lot of FORTRAN,
For science it worked flawlessly.
Try using it for graphics!
Write in C.

If you've just spent nearly 30 hours
Debugging some assembly,
Soon you will be glad to
Write in C.

Write in C, Write in C,
Write in C, yeah, Write in C.
Only wimps use BASIC.
Write in C.

Write in C, Write in C
Write in C, oh, Write in C.
Pascal won't quite cut it.
Write in C.

Write in C, Write in C,
Write in C, yeah, Write in C.
Don't even mention COBOL.
Write in C.
__________________
Quote:
Originally posted by Bloomers III
sex is dirty and for losers who can't masturbate properly
Pitchfork is offline   Reply With Quote
Unread 12 Apr 2003, 13:00   #6
xtothez
ŻŻŻŻŻŻŻŻŻ
 
xtothez's Avatar
 
Join Date: May 2001
Location: Sept 2057
Posts: 1,813
xtothez has much to be proud ofxtothez has much to be proud ofxtothez has much to be proud ofxtothez has much to be proud ofxtothez has much to be proud ofxtothez has much to be proud ofxtothez has much to be proud ofxtothez has much to be proud ofxtothez has much to be proud ofxtothez has much to be proud of
Updating as you go will always be too slow for this sort of thing, no matter how you write it. My first attempt at a planets parser took about a minute to do the full DB, and that was without advanced stats like roid losses and score history. Either make an array in PHP then load/unload with that, or better yet - use C.
__________________
in my sig i write down all my previous co-ords and alliance positions as if they matter because I'm not important enough to be remembered by nickname alone.
xtothez is offline   Reply With Quote
Unread 12 Apr 2003, 14:10   #7
queball
Ball
 
queball's Avatar
 
Join Date: Oct 2001
Posts: 4,410
queball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so little
Quote:
Originally posted by Mit
It will take a while, a suggestion, that was actually given to me, was to work in RAM. Save teh entire universe in an array, change stuff and update once per plent instead of 8 times it would have been for me and the official tools. One hell of a lot quicker.

Each planet has an idividual ID, thats how i reference it.
MySQL will do this if it's appropriate, and it will do it much better and faster than you could, while providing any transaction semantics you have specified.

The bonus of only having two queries (select *, copy from stdin) is only there because Gayle is doing one query per planet, which is what she's (I assume) asking for a clever idea for.

As for using C... I never understand how people can look and a program that spends something like 0.1% of its time in code and 99.9% of its time waiting on external processes, and say that another language should be used.

Gayle, a few ways I've gone about doing this sort of thing in MySQL are:
- insert each sorted cluster into a temporary table with an autoincrement, then load back
- use a variable so select x,y,z,@a=@a+1 (sorry, can't remember the exact syntax offhand)
- use (cluster, score) as an index and calculate the rank dynamicly each time
One of these might work for you. If that still doesn't give you enough speed, you could try the optimising tips in the manual, or upgrade to MSSQL.
__________________
#linux
queball is offline   Reply With Quote
Unread 12 Apr 2003, 15:25   #8
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
weeeeeeh, it works in under a second now for all the planets

Indexing by x,y,z helps a bit

[edit]Timed at 7 seconds for universe/cluster/para/galaxy rankings for both planets and gals. Much faster than the unindexed version [/edit]
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!

Last edited by Gayle29uk; 12 Apr 2003 at 18:42.
Gayle29uk is offline   Reply With Quote
Unread 14 Apr 2003, 22:38   #9
Starbucks
It was a Stupid Dream
 
Starbucks's Avatar
 
Join Date: Jun 2002
Location: Winchester, UK
Posts: 2,077
Starbucks is on a distinguished road
am i the only one that uses SAP.net as a database system????















thought so
Starbucks is offline   Reply With Quote
Unread 15 Apr 2003, 08:33   #10
Pitchfork
Tourist
 
Join Date: Jun 2001
Location: moon
Posts: 90
Pitchfork is an unknown quantity at this point
Quote:
Originally posted by Starbucks
am i the only one that uses SAP.net as a database system????















thought so
I thought about trying it, but I stuck to postgreSQL
__________________
Quote:
Originally posted by Bloomers III
sex is dirty and for losers who can't masturbate properly
Pitchfork is offline   Reply With Quote
Unread 15 Apr 2003, 13:46   #11
Raging.Retard
Street Tramp
 
Raging.Retard's Avatar
 
Join Date: Apr 2000
Location: Street Gutter
Posts: 341
Raging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant future
Your original script looks slow and ive not even tried it . The only way your going to get extreme speed is to not pull any data back from the DB, as queball said.

Hoewever, as a quick performance change to your current script, open your database connection outside the loop, and only issue the changing query inside the loop (this removes the overhead of repeated connection negotiation, be it named pipe/tcp - I dont know how MySQL works).

As for your indexing ... of course it woud help Though to be honest, it would have been better to have made x,y,z your primary key from the start which impiles an index on them anyway.

All said.. You should really try to not pull data back from the DB at all. Databases are there for storing and processing data. Theres little point in you trying to do it, when thats its job. As quey said, it will most likely do it quicker (and more importantly, with less code to write!).

SELECT plandump.*, (SELECT COUNT(*) FROM plandump AS planindexer WHERE planindexer.size > plandump.size) + 1 AS Rank
FROM plandump

(No idea in MySQL but in TSQL 'Size' is a keyword btw).

That statement will return your data with a Rank field showing its associated rank. Im sure you can work the UPDATE statmenet from it, should that be your goal. That statement took < 1 sec to Rank 8,000s plants on a cache hit on my old machine (p3/600). Approx 1.5 secs on cache miss.

Incidentally ive posted the execution plan which can be found (here). You can see that the query spends 67% (the majority of the query) of its time in the Index Spool / Eager Spool Stage... without your pre orderd index, that has to be done on the fly, which is why your performance sufferd orginally (Although query is diff, it still data spools in same way).
__________________
Chimney Pots.
Raging.Retard is offline   Reply With Quote
Unread 15 Apr 2003, 14:10   #12
Pitchfork
Tourist
 
Join Date: Jun 2001
Location: moon
Posts: 90
Pitchfork is an unknown quantity at this point
Quote:
Originally posted by Raging.Retard
...
SELECT plandump.*, (SELECT COUNT(*) FROM plandump AS planindexer WHERE planindexer.size > plandump.size) + 1 AS Rank
FROM plandump
...
No Subqueries in MySQL unfortunately
__________________
Quote:
Originally posted by Bloomers III
sex is dirty and for losers who can't masturbate properly
Pitchfork is offline   Reply With Quote
Unread 15 Apr 2003, 14:22   #13
Raging.Retard
Street Tramp
 
Raging.Retard's Avatar
 
Join Date: Apr 2000
Location: Street Gutter
Posts: 341
Raging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant future
Quote:
Originally posted by Pitchfork
No Subqueries in MySQL unfortunately
If thats true... this just confirms that MySQL is a joke . Its about as much of a DB server as notepad.
__________________
Chimney Pots.
Raging.Retard is offline   Reply With Quote
Unread 15 Apr 2003, 16:28   #14
ItotheDtotheI
Guest
 
Posts: n/a
MySQL DOES support subqueries.

kthxbye
  Reply With Quote
Unread 15 Apr 2003, 16:57   #15
pablissimo
Henry Kelly
 
pablissimo's Avatar
 
Join Date: Apr 2000
Posts: 7,374
pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.pablissimo has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
http://www.mysql.com/doc/en/ANSI_diff_Sub-selects.html
__________________
You're now playing ketchup
pablissimo is offline   Reply With Quote
Unread 15 Apr 2003, 16:57   #16
Pitchfork
Tourist
 
Join Date: Jun 2001
Location: moon
Posts: 90
Pitchfork is an unknown quantity at this point
Quote:
Originally posted by ItotheDtotheI
MySQL DOES support subqueries.

kthxbye
Quote:
http://www.mysql.com/doc/en/ANSI_diff_Sub-selects.html
Subqueries are supported in MySQL version 4.1.
Quote:
http://www.mysql.com/press/release_2003_10.html
MySQL AB Confirms Version 4.0.12 Ready for all Application Areas
Quote:
http://lists.mysql.com/list.php?list=announce&post=161
MySQL 4.1.0 has been released
...
As this code is currently labelled "Alpha", we
do not recommend that this version be used in production environments yet!
So indeed it does more or less. But did you ever tried to use a mySQL Alpha? I did once...

[Edit] I have to apologize for bein outdated six days, but heh, I don't use mySql [/Edit]
__________________
Quote:
Originally posted by Bloomers III
sex is dirty and for losers who can't masturbate properly
Pitchfork is offline   Reply With Quote
Unread 15 Apr 2003, 16:59   #17
ItotheDtotheI
Guest
 
Posts: n/a
Quote:
Originally posted by Pitchfork
So indeed it does more or less. But did you ever tried to use a mySQL Alpha? I did once...
yes

nothing bad happened to me.
  Reply With Quote
Unread 15 Apr 2003, 17:04   #18
Pitchfork
Tourist
 
Join Date: Jun 2001
Location: moon
Posts: 90
Pitchfork is an unknown quantity at this point
Quote:
Originally posted by ItotheDtotheI
yes

nothing bad happened to me.
hmz, mine kept crashing about once per hour, was a 3.something alpha though
__________________
Quote:
Originally posted by Bloomers III
sex is dirty and for losers who can't masturbate properly
Pitchfork is offline   Reply With Quote
Unread 23 Apr 2003, 16:25   #19
MT
/dev/zero
Retired Mod
 
MT's Avatar
 
Join Date: May 2000
Posts: 415
MT is an unknown quantity at this point
Quote:
Originally posted by Raging.Retard
If thats true... this just confirms that MySQL is a joke . Its about as much of a DB server as notepad.
You think you are so cool with your MSQL server licence...

MySQL is fast at selects and inserts. Thats about it. Its a SQL front end to flat file databases, and a damn good one at that, but for advanced SQL manipulations, you will always be better off with something else.

Not Filemaker PRO either!
__________________
#linux : Home of Genius

<idimmu> ok i was chained to a desk with this oriental dude
MT is offline   Reply With Quote
Unread 25 Apr 2003, 02:44   #20
Raging.Retard
Street Tramp
 
Raging.Retard's Avatar
 
Join Date: Apr 2000
Location: Street Gutter
Posts: 341
Raging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant future
Quote:
Originally posted by MT
You think you are so cool with your MSQL server licence...
Its not about being 'cool'. Its about showing people not all MS products are bad, despite what they may think. That one just happens to be one of their better, and a pretty competetive application at that. I wouldnt do it as much if people didnt worship MySQL as much, like some magnificent database engine sent from god. (Yeah its free... blah blah.. PostgreSQL anyone?).

Quote:
Originally posted by MT
MySQL is fast at selects and inserts. Thats about it. Its a SQL front end to flat file databases, and a damn good one at that, but for advanced SQL manipulations, you will always be better off with something else.
When I consider even MS Access supports subqueries, which is.... 'a SQL front end to flat file database'... , it cant help but bring a smile to my face. Subqueries are not an 'advanced SQL manipulations' they are trivial operations, in the same category as table joins. Pretty important in a relational database, infact I really cant see why anyone in their right mind would leave them out.

Innit.
__________________
Chimney Pots.
Raging.Retard is offline   Reply With Quote
Unread 25 Apr 2003, 02:49   #21
ItotheDtotheI
Guest
 
Posts: n/a
:debian-legal: dont like MSSQL, so neither do I.
  Reply With Quote
Unread 25 Apr 2003, 02:51   #22
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
The DB is MySQL 3.x. Having learnt a lot about handling 'significant' sized databases during this project I would happily trade it for postgresql and it's nested SQL statements any day

My hosting provider doesn't do psql though.
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline   Reply With Quote
Unread 25 Apr 2003, 03:26   #23
queball
Ball
 
queball's Avatar
 
Join Date: Oct 2001
Posts: 4,410
queball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so little
Quote:
Originally posted by Raging.Retard

When I consider even MS Access supports subqueries, which is.... 'a SQL front end to flat file database'... , it cant help but bring a smile to my face. Subqueries are not an 'advanced SQL manipulations' they are trivial operations, in the same category as table joins. Pretty important in a relational database, infact I really cant see why anyone in their right mind would leave them out.
Hardly the same category as table join, since without table joins it would be a useless language.

Are you lot really so lazy that a feature like subselects constrains your choice of database? Something like the lack of a non-blocking API is understandable, but subselects?

I know it's naive to apply an academic view to everything, but really the fundamentals of using an relational database are an understanding of tuples, joins, indeces and transactions. Subselects are a common idiom so it's nice that MSSQL provides a simple way to deal with them, which lets MSSQL do its query optimisation magic, but they are hardly fundamental. And I know DB admins like to rant about referential integrity, and whatever, but foreign keys can be done outside too.

Things like a query analyser are nice. You can get at least one for MySQL, too, but it turns out they are rarely used: the expert chooses his operations well. If optimisation is needed, tools are fine, but something more flexible is usually required anyway.

I only hear complaints like this from people learning MySQL and PHP and writing a k-rad dynamic website. I've never found MySQL's missing features a problem in my own apps. Not that this really matters anymore with the release of 4.1.
queball is offline   Reply With Quote
Unread 25 Apr 2003, 20:54   #24
Raging.Retard
Street Tramp
 
Raging.Retard's Avatar
 
Join Date: Apr 2000
Location: Street Gutter
Posts: 341
Raging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant future
Quote:
Originally posted by queball
Hardly the same category as table join, since without table joins it would be a useless language.
All joins can be expressed as a single or series of subqueries, not all subqueries can be expressed as table joins. So if for some bizare reason you only implemented subqueries, you have not lost any functionality of your system. I would indeed rank subselects with the same importance as table joins.

Obviously there is the issue of performance, there is usually no performance difference between a query that includes a subquery and a semantically equivalent version using table joins that doesnt. Only in cases where existence must be checked, a join will give better performance (Otherwise the nested query must be processed for each result of the outer query to ensure elimination of duplicates, which is obviously slower).

Not only are subselects 'a common idiom', they are also part of the ANSI SQL 92 standard. I know .. I know.. that this goes back to the old argument of just how many DB's are actually SQL92 complient, but as its my view that subqueries are of such fundamental importance to the language, I cant understand why they chose to leave it out for so long. Still, like you said, not that it matters now.
__________________
Chimney Pots.
Raging.Retard is offline   Reply With Quote
Unread 26 Apr 2003, 23:49   #25
queball
Ball
 
queball's Avatar
 
Join Date: Oct 2001
Posts: 4,410
queball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so little
Quote:
Originally posted by Raging.Retard
All joins can be expressed as a single or series of subqueries
I'm intrigued, how would this work?
Like how would you do "SELECT * FROM a, b" with subqueries.
queball is offline   Reply With Quote
Unread 27 Apr 2003, 04:12   #26
Raging.Retard
Street Tramp
 
Raging.Retard's Avatar
 
Join Date: Apr 2000
Location: Street Gutter
Posts: 341
Raging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant futureRaging.Retard has a brilliant future
Quote:
Originally posted by queball
I'm intrigued, how would this work?
Like how would you do "SELECT * FROM a, b" with subqueries.
I suspected I would be asked to prove it

Personally I dont like the join implied by 'SELECT * FROM a, b' I prefer the equivilent (yet in my opinion, semantically clearer) version below:

SELECT * FROM a INNER JOIN b ON 1=1

Still I guess thats just a taste thing.

That query can expressed as a subquery as follows:

SELECT *, (SELECT *FROM b) FROM a

The flaw in the plan, is that although this is valid SQL, a fair few (relational anyway) DB servers (my favourd MS included), do not support using subqueries as expressions directly in the SELECT when the subquery returns more than one row (ie, a non atomic result). This is obviously only restrictive to expressions, not applying to a subselect as part of an IN clause (as that would be silly).
__________________
Chimney Pots.
Raging.Retard is offline   Reply With Quote
Unread 27 Apr 2003, 04:48   #27
queball
Ball
 
queball's Avatar
 
Join Date: Oct 2001
Posts: 4,410
queball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so little
Indeed, and as far as I can see that would just be an implicit join. Can you come up with an expression with subqueries that can't be expressed with a few joins?
queball is offline   Reply With Quote
Unread 27 Apr 2003, 05:19   #28
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Quote:
Originally posted by Raging.Retard
As for your indexing ... of course it woud help Though to be honest, it would have been better to have made x,y,z your primary key from the start which impiles an index on them anyway.
Re-reading this thread I have to query that. How on Earth can x,y,z be primary keys when they're not unique?
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline   Reply With Quote
Unread 27 Apr 2003, 05:32   #29
queball
Ball
 
queball's Avatar
 
Join Date: Oct 2001
Posts: 4,410
queball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so little
Quote:
Originally posted by Gayle29uk
Re-reading this thread I have to query that. How on Earth can x,y,z be primary keys when they're not unique?
(x,y,z) IS unique though, if you have one row per planet... the key is a combination ("tuple") of the relevant fields. Just like if you had a primary key of CONCAT(x, ",", y, ",", z), except better.
queball is offline   Reply With Quote
Unread 27 Apr 2003, 05:37   #30
Gayle29uk
Bitch
 
Join Date: Jun 2002
Location: North Yorkshire
Posts: 3,848
Gayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really niceGayle29uk is just really nice
Quote:
Originally posted by queball
(x,y,z) IS unique though, if you have one row per planet... the key is a combination ("tuple") of the relevant fields. Just like if you had a primary key of CONCAT(x, ",", y, ",", z), except better.
Didn't know you could have a multi field primary key, you learn something new every day

Although as the current dump is in it's own table with an auto_increment ID as primary key (indexed by x,y,z) I'm not sure it's much use to me. Certainly not in the history file as x,y,z is not unique in there.
__________________
ACHTUNG!!!
Das machine is nicht fur gefingerpoken und mittengrabben. Ist easy
schnappen der springenwerk, blowenfusen und corkenpoppen mit
spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das
rubbernecken sightseeren keepen hands in das pockets. Relaxen und vatch
das blinkenlights!!!
Gayle29uk is offline   Reply With Quote
Unread 27 Apr 2003, 06:01   #31
queball
Ball
 
queball's Avatar
 
Join Date: Oct 2001
Posts: 4,410
queball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so little
Quote:
Originally posted by Gayle29uk
Didn't know you could have a multi field primary key, you learn something new every day

Although as the current dump is in it's own table with an auto_increment ID as primary key (indexed by x,y,z) I'm not sure it's much use to me. Certainly not in the history file as x,y,z is not unique in there.
I don't believe there's any difference between a primary key and a unique key in terms of speed. It really depends on the kind of queries you'll do but if I had a history database I'd go for a primary key on (x,y,z,t), keys on (x,y,z), (score,t) and (size,t), just as a guess (and I'd have a profiler and ALTER ready as soon as some PHP is sorted out). Insert speed be damned .
queball is offline   Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 20:27.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright İ2002 - 2018