Dear mysql-ians,
I am performing a query that takes ages before showing a result. I
suppose it is very time consuming because of the JOIN I perform. My
question therefore is if you have any suggestions to optimize my query?
What I want to do is divide a value of a cell (NDVI) by the median of
its neighbours based on geographical coordinates (refgeo).
The selection script is as follows:
SELECT
NDVI.id,
NDVI.NDVI_99_24*IF(B.B_99_24<30,1,NULL)/MEDIAN(refNDVI.NDVI_99_24*IF(refB.B_99_24<30,1,NUL L)),
NDVI.NDVI_99_25*IF(B.B_99_25<30,1,NULL)/MEDIAN(refNDVI.NDVI_99_25*IF(refB.B_99_25<30,1,NUL L)),
NDVI.NDVI_99_26*IF(B.B_99_26<30,1,NULL)/MEDIAN(refNDVI.NDVI_99_26*IF(refB.B_99_26<30,1,NUL L)),
....,
NDVI.NDVI_99_170*IF(B.B_99_170<30,1,NULL)/MEDIAN(refNDVI.NDVI_99_170*IF(refB.B_99_170<30,1,N ULL))
FROM vgt.NDVI AS NDVI
INNER JOIN vgt.B AS B
USING (id)
INNER JOIN vgt.v_ecoclim AS eco
USING (id)
INNER JOIN vgt.v_vcf2001 AS vcf
USING (id)
,
(vgt.meta_gsc AS refmgsc
INNER JOIN vgt.gsc AS refgsc
ON refgsc.gsc_XX = refmgsc.id)
INNER JOIN vgt.geo AS refgeo
ON refgeo.id = refgsc.id
INNER JOIN vgt.B AS refB
ON refgeo.id = refB.id
INNER JOIN vgt.v_ecoclim AS refeco
ON refgeo.id = refeco.id
INNER JOIN vgt.v_vcf2001 AS refvcf
ON refgeo.id = refvcf.id
INNER JOIN (vgt.gba AS refgba
INNER JOIN vgt.meta_gba AS refmgba
ON refgba.gba_XX = refmgba.id)
ON refgeo.id=refgba.id
INNER JOIN vgt.NDVI AS refNDVI
ON refgeo.id = refNDVI.id
WHERE NDVI.id= 1133568
AND refgeo.X_coord > 1288
AND refgeo.X_coord < 1328
AND refgeo.Y_coord > 659
AND refgeo.Y_coord < 699
AND refmgba.burnt=0
AND refmgsc.burnt=0
AND refeco.v_landcov=eco.v_landcov
AND refeco.v_lowreb=eco.v_lowreb
AND refvcf.vcf_bare < vcf.vcf_bare+20
AND refvcf.vcf_bare > vcf.vcf_bare-20
AND refvcf.vcf_tree < vcf.vcf_tree+20
AND refvcf.vcf_tree > vcf.vcf_tree-20
AND refvcf.vcf_herb < vcf.vcf_herb+20
AND refvcf.vcf_herb > vcf.vcf_herb-20
GROUP BY refmgba.burnt
I have thus several main-tables that have identical rows (and are
linked by id in a 1to1-relatioship ) and I have 2 sub-tables in a
manyto1-relationship. I have put it in a scheme below (view using
Courier font for correct spacing).
The main tables are: NDVI, B, eco, vcf, refgsc, refgeo, refeco, refgba,
refB, refvcf, refNDVI.
The 2 subtables: refmgba, refmgsc.
Is my query correct? Do you have any solutions to make my query more
efficient?
I've studied the mysql-manual, but I don't see answers on the moment
Thanks in advance,
Stef
Schematic overview tables:
[=============] [=============] [============]
[T_Main: gsc ] [T_Main: gba ] [T_Main:NDVI ] O
[=============] [=============] [============] T
[ ID ]<--->[ ID ]<->[ ID ]<->H
|-->[ gsc_XX(many)] |->[ gba_XX(many)] [ NDVI_99_24 ] E
| [ Others... ] | [ Others... ] [ NDVI_99_25 ] R
| [=============] | [=============] [ Others... ] S
| | [============]
| |
| |
| [=============] | [=============]
| [T: refmgsc ] | [T: refmgba ]
| [=============] | [=============]
|--> [ ID(1) ] |--> [ ID(1) ]
[ BURNT ] [ BURNT ]
[ Others... ] [ Others... ]
[=============] [=============] 1 1772 st***************@agr.kuleuven.ac.be wrote: Dear mysql-ians,
I am performing a query that takes ages before showing a result. I suppose it is very time consuming because of the JOIN I perform. My question therefore is if you have any suggestions to optimize my query?
What I want to do is divide a value of a cell (NDVI) by the median of its neighbours based on geographical coordinates (refgeo). The selection script is as follows:
SELECT NDVI.id,
NDVI.NDVI_99_24*IF(B.B_99_24<30,1,NULL)/MEDIAN(refNDVI.NDVI_99_24*IF(refB.B_99_24<30,1,NUL L)),
NDVI.NDVI_99_25*IF(B.B_99_25<30,1,NULL)/MEDIAN(refNDVI.NDVI_99_25*IF(refB.B_99_25<30,1,NUL L)),
NDVI.NDVI_99_26*IF(B.B_99_26<30,1,NULL)/MEDIAN(refNDVI.NDVI_99_26*IF(refB.B_99_26<30,1,NUL L)), ....,
NDVI.NDVI_99_170*IF(B.B_99_170<30,1,NULL)/MEDIAN(refNDVI.NDVI_99_170*IF(refB.B_99_170<30,1,N ULL))
FROM vgt.NDVI AS NDVI INNER JOIN vgt.B AS B USING (id) INNER JOIN vgt.v_ecoclim AS eco USING (id) INNER JOIN vgt.v_vcf2001 AS vcf USING (id) , (vgt.meta_gsc AS refmgsc INNER JOIN vgt.gsc AS refgsc ON refgsc.gsc_XX = refmgsc.id) INNER JOIN vgt.geo AS refgeo ON refgeo.id = refgsc.id INNER JOIN vgt.B AS refB ON refgeo.id = refB.id INNER JOIN vgt.v_ecoclim AS refeco ON refgeo.id = refeco.id INNER JOIN vgt.v_vcf2001 AS refvcf ON refgeo.id = refvcf.id INNER JOIN (vgt.gba AS refgba INNER JOIN vgt.meta_gba AS refmgba ON refgba.gba_XX = refmgba.id) ON refgeo.id=refgba.id INNER JOIN vgt.NDVI AS refNDVI ON refgeo.id = refNDVI.id WHERE NDVI.id= 1133568 AND refgeo.X_coord > 1288 AND refgeo.X_coord < 1328 AND refgeo.Y_coord > 659 AND refgeo.Y_coord < 699 AND refmgba.burnt=0 AND refmgsc.burnt=0 AND refeco.v_landcov=eco.v_landcov AND refeco.v_lowreb=eco.v_lowreb AND refvcf.vcf_bare < vcf.vcf_bare+20 AND refvcf.vcf_bare > vcf.vcf_bare-20 AND refvcf.vcf_tree < vcf.vcf_tree+20 AND refvcf.vcf_tree > vcf.vcf_tree-20 AND refvcf.vcf_herb < vcf.vcf_herb+20 AND refvcf.vcf_herb > vcf.vcf_herb-20 GROUP BY refmgba.burnt
I have thus several main-tables that have identical rows (and are linked by id in a 1to1-relatioship ) and I have 2 sub-tables in a manyto1-relationship. I have put it in a scheme below (view using Courier font for correct spacing).
The main tables are: NDVI, B, eco, vcf, refgsc, refgeo, refeco, refgba, refB, refvcf, refNDVI. The 2 subtables: refmgba, refmgsc.
Is my query correct? Do you have any solutions to make my query more efficient? I've studied the mysql-manual, but I don't see answers on the moment
Thanks in advance, Stef
Schematic overview tables:
[=============] [=============] [============] [T_Main: gsc ] [T_Main: gba ] [T_Main:NDVI ] O [=============] [=============] [============] T [ ID ]<--->[ ID ]<->[ ID ]<->H |-->[ gsc_XX(many)] |->[ gba_XX(many)] [ NDVI_99_24 ] E | [ Others... ] | [ Others... ] [ NDVI_99_25 ] R | [=============] | [=============] [ Others... ] S | | [============] | | | | | [=============] | [=============] | [T: refmgsc ] | [T: refmgba ] | [=============] | [=============] |--> [ ID(1) ] |--> [ ID(1) ] [ BURNT ] [ BURNT ] [ Others... ] [ Others... ] [=============] [=============]
make sure you have indexes that support your where-clause. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ArShAm |
last post by:
Hi there
Please help me to optimize this code for speed
I added /O2 to compiler settings
I added /Oe to compiler settings for accepting register type request , but
it seems that is not allowed...
|
by: Soefara |
last post by:
Dear Sirs,
I am experiencing strange results when trying to optimize a LEFT JOIN
on 3 tables using MySQL.
Given 3 tables A, B, C such as the following:
create table A (
uniqueId int not...
|
by: Ron Johnson |
last post by:
On Mon, 2003-08-25 at 16:28, Gregory S. Williamson wrote:
> One of our sysads sent this link ... wondering if there is any comment on it from the world of actual users of linux and a database.
>
>...
|
by: Vendell |
last post by:
Join one of Canada's finest business men...
Dear entrepreneur colleague:
Here is a message from the founder....
Let me introduce myself. My name is Ariel Topf. I am 42 years old and I have...
|
by: frizzle |
last post by:
Hi there,
I'm building a forum with a mysql backend. The forum has the following
structure:
- category
|--> forum
|--> thread
|--> replies
Once the user has defined a forum (id), i first...
|
by: Richard G. Riley |
last post by:
Without resorting to asm chunks I'm working on a few small routines
which manipulate bitmasks. I'm looking for any guidance on writing C
in a manner which tilts the compilers hand in, if possible,...
|
by: mamapossible |
last post by:
Hi, I've spent hours trying to optimize this simple query:
SELECT count(sites_jobs.id) as jobCount,
sites_jobs_categories.frn_site_id, sites_jobs_categories.id,
sites_jobs_categories.name,...
|
by: Mark E. Fenner |
last post by:
Hello all,
I have a code where my inner loop looks like:
allNew =
for params in cases:
newObj = copy(initialObject)
newObj.modify(params)
allNew.append(newObj)
return allNew
|
by: erbrose |
last post by:
Hello All!
Hoping some folks could help me optimize and or choose the best route to do this process.
First off, here is what I am trying to achieve. I have a (fairly large) table of ~34million rows...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |