Re: how can i make this query run faster
From: Ivan Arjentinski (jarj11-at-hotmail.com)
Date: 12/29/04
- Next message: Erland Sommarskog: "Re: Foreign keys"
- Previous message: --CELKO--: "Re: Offsetting data"
- In reply to: Erland Sommarskog: "Re: how can i make this query run faster"
- Next in thread: Gert-Jan Strik: "Re: how can i make this query run faster"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 30 Dec 2004 01:31:19 +0200
> INSERT tbl (col1, col2, col3,
> col4,
> col5, col6,
> ...
> SELECT col1, col2, col3,
> <some long expression resulting in col 4>,
> <half-long expre for col5>, <ditto for col6>,
I do the following:
--(Variant 1)
INSERT tbl (
col1,
col2,
col3,
col4,
col5,
col6,
...
SELECT
t1.col1,
t2.col2,
t1.col3,
<some long expression resulting in col 4> AS col4,
<half-long expre for col5> AS col5,
<ditto for col6> AS col6,
...
Note the "AS colX" rename. This is not required, but really helps keeping
the two lists in sync.
Sometimes, for long column lists, in order to further emphasize the rename I
even do:
--(Variant 2)
INSERT tbl (
col1,
col2,
col3,
col4,
col5,
col6,
...
SELECT
t1.col1 AS col1,
t2.col2 AS col2,
t1.col3 AS col3,
<some long expression resulting in col 4> AS col4,
<half-long expre for col5> AS col5,
<ditto for col6> AS col6,
...
so that if someone, for example, changes the column t1.col1 to expression,
the rename "AS col1" stays intact.
And finally, to be truly honest I even further emphasize the rename with
this:
--(Variant 3)
INSERT tbl (
col1,
col2,
col3,
col4,
col5,
col6,
...
SELECT
t1.col1 AS col1_,
t2.col2 AS col2_,
t1.col3 AS col3_,
<some long expression resulting in col 4> AS col4_,
<half-long expre for col5> AS col5_,
<ditto for col6> AS col6_,
so that if someone else comes and tries to maintain the code to easily
understand (without asking me) that this is just a rename and no other
tricks are involved.
Maybe the last case is an extreme, but I really think that code readibility
and maintainability are one of the most important things to follow when
creating code.
-- Ivan Arjentinski
- Next message: Erland Sommarskog: "Re: Foreign keys"
- Previous message: --CELKO--: "Re: Offsetting data"
- In reply to: Erland Sommarskog: "Re: how can i make this query run faster"
- Next in thread: Gert-Jan Strik: "Re: how can i make this query run faster"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|