These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

EVE Technology Lab

 
  • Topic is locked indefinitely.
 

Is there a better way to write this query?

First post
Author
Rune Mangeiri
Soltech Armada
Minmatar Fleet Alliance
#1 - 2015-10-08 00:07:13 UTC
I have been messing around with data base query's on the eve static data. I wanted to get certain info from towers and this is what I came up with so far.
SELECT
  Names.[typeID]  AS ID,
  Names.[typeName] AS Name, 
  COALESCE(
    HP.[valueFloat],
    HP.[valueInt]
  ) AS Structure, 
  COALESCE( 
    ArmorHP.[valueFloat],   
    ArmorHP.[valueInt]
  ) AS Armor, 
  COALESCE(
    ShieldHP.[valueFloat],   
    ShieldHP.[valueInt]
  ) AS Sheild, 
  COALESCE(
    PWG.[valueFloat],   
    PWG.[valueInt]
  ) AS PowerGrid, 
  COALESCE(
    Tf.[valueFloat],   
    Tf.[valueInt]
  ) AS CPU
FROM invTypes AS Names
INNER JOIN dgmTypeAttributes As HP
  ON Names.[typeID] = HP.[typeID]   
  AND HP.[attributeID] = 9 
INNER JOIN dgmTypeAttributes AS ArmorHP
  ON Names.[typeID] = ArmorHP.[typeID] 
  AND ArmorHP.[attributeID] = 265 
INNER JOIN dgmTypeAttributes AS ShieldHP
  ON ShieldHP.[typeID] = Names.[typeID] 
  AND ShieldHP.[attributeID] = 263 
INNER JOIN dgmTypeAttributes AS PWG
  ON Names.[typeID] = PWG.[typeID] 
  AND PWG.[attributeID] = 11 
INNER JOIN dgmTypeAttributes AS Tf
  ON Names.[typeID] = Tf.[typeID] 
  AND Tf.[attributeID] = 48
WHERE
  Names.[groupID] = 365
  AND Names.[published] = 1
  AND Names.[typeID] != 4361;


It returns the information in the format that I want it to be in, but it seems a little long. I was wondering if there was a better way to get the same result? Just really interested to see if I can add some techniques for my mental toolbox.
CCP Tellus
C C P
C C P Alliance
#2 - 2015-10-08 00:13:06 UTC
That query looks pretty much optimized already, and well written (kudos to you). You may want to check if you have indexes on the typeID column in dgmTypeAttributes, and groupID in invTypes; those are likely to improve your query's performance if you don't have those indexes already.
Rune Mangeiri
Soltech Armada
Minmatar Fleet Alliance
#3 - 2015-10-08 00:23:42 UTC
Great! Thanks for the reply. Well I Guess if anyone needs a query returns the following tower info:

typeID, typeName, Structure, Armor, Shield

Feel free to use this one. I know looking at examples helps learn from first hand experience.
Aurelia Manbeater
EVE-Operations
#4 - 2015-10-09 08:42:04 UTC
use your query to create a blank new table with the data you need and update it if needed.
doing your production querys over that table will be much faster