English 中文(简体)
我如何能够改进这种多面的同mon问?
原标题:How can I improve this multiple join monster query?
  • 时间:2011-11-21 15:05:14
  •  标签:
  • mysql

为了你的利益,我不要gon,我们在这里都知道,它会长期 h,而且会有许多人加入。

该表的结构是一米,在最复杂的情况下开展工作:

tables = Co, Cn, O, A, N;
scheme (simplified):
N(n)-> (1)every other table
A(n)-> (1)(every other table except N
O(n)-> (1)Co, Cn
Cn(n) -> (1)Co
Co(1) -> (1)cn

问题中最困难的部分是这种结构(试图从表N获取信息,但也从表N获取信息):

N join A join O join ((Co join Cn) union (Cn join Co ))

我需要从N那里获得内容,但我也需要从C和Cn那里 st,但我必须走强的A和O才能获得这些内容。 现在,这似乎并不像一个巨大的疑问,但N也可能与所有其他表格中的每一个表格有关,我需要将它们归到一起;如果我重复的话,我就看问题的内容。 我与每个案件分开审理(N->A, N->O, N->Cn,等),然后用“UNION” gr。

目前,在N,有近20万条线,在另一张表格中,每张数据库服务器和网站在我试图管理提问时,仅hang。

我认为的一种解决办法是, d弄外国钥匙,为连接打下一个空间,例如从N trough等人那里走过来:“A_IdA,O_IdO,Co_IdCo,Cn_IdCn”,并在php中处理;但是,在桌设计发生如此巨大变化之前,我只尝试了其他东西。

问题回答

我花了一段艰难的时间,试图掌握你的确切桌子结构和问话。

然而,我感到,你想把太多的精力合并到1个问题,使加入成为非行服务器的极端压力。 你最有可能更好地进行多种更简单的询问,然后试图在1个大问题中这样做。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签