2012-05-31 3 views
0

편집 :mysql : 동일한 쿼리, 다른 결과

나는 쿼리 마감일을 보냈다. 이 쿼리를 두 개의 작은 쿼리로 나누고 Java에서 비즈니스 로직을 수행함으로써 문제를 해결할 수있었습니다. 이 쿼리가 임의의 시간에 두 가지 결과를 반환 할 수있는 이유를 알고 싶습니다.

따라서 임의의 예상 결과를 모두 무작위로 반환하고, 다른 절반은 반으로 만듭니다. 내가 조인 당 하나의 조인을 작성하고 각 조인 후에 실행하면 결국 모든 예상 된 결과를 리턴한다는 것을 알아 챘습니다. 그래서 어떤 종류의 MySql 메모리 또는 다른 제한 사항이 조인에서 전체 테이블을 차지하지 않는다면 방황하고 있습니다. 또한 비 결정적 쿼리를 읽지 만 무엇을 말할 지 확신하지 못합니다.

명확한 설명이 필요한 경우 도움을 요청하고 사전에 감사드립니다.

RESET QUERY CACHE; 

SET SQL_BIG_SELECTS=1; 

set @displayvideoaction_id = 2302; 
set @ticSessionId = 3851; 


select richtext.id,richtextcross.name,richtextcross.updates_demo_field,richtext.content from 
(
select listitemcross.id,name,updates_demo_field,listitem.text_id from 
(
select id,name, updates_demo_field, items_id from 
(
SELECT id, name, answertype_id, updates_demo_field, 
@student:=CASE WHEN @class <> updates_demo_field THEN 0 ELSE @student+1 END AS rn, 
@class:=updates_demo_field AS clset FROM 
(SELECT @student:= -1) s, 
(SELECT @class:= '-1') c, 
(
select id, name, answertype_id, updates_demo_field from 
(
select manytomany.questions_id from 
(
select questiongroup_id from 
(
select questiongroup_id from `ticnotes`.`scriptaction` where [email protected] and questiongroup_id is not null 
) scriptaction 
inner join 
(
select * from `ticnotes`.`questiongroup` 
) questiongroup on scriptaction.questiongroup_id=questiongroup.id 
) scriptgroup 
inner join 
(
select * from `ticnotes`.`questiongroup_question` 
) manytomany on scriptgroup.questiongroup_id=manytomany.questiongroup_id 
) questionrelation 
inner join 
(
select * from `ticnotes`.`question` 
) questiontable on questionrelation.questions_id=questiontable.id 
where updates_demo_field = 'DEMO1' or updates_demo_field = 'DEMO2' 
order by updates_demo_field, id desc 
) t 
having rn=0 
) firstrowofgroup 
inner join 
(
select * from `ticnotes`.`multipleoptionstype_listitem` 
) selectlistanswers on firstrowofgroup.answertype_id=selectlistanswers.multipleoptionstype_id 
) listitemcross 
inner join 
(
select * from `ticnotes`.`listitem` 
) listitem on listitemcross.items_id=listitem.id 
) richtextcross 
inner join 
(
select * from `ticnotes`.`richtext` 
) richtext on richtextcross.text_id=richtext.id; 
+4

이것은 완전히 읽을 수 없습니다. 나는 두 가지 질문이 있는지조차 알 수 없다. 더 나은 형식을 지정하십시오. –

+0

하나의 질문은 지금 읽을 수 있습니까? –

답변

4

제 첫 인상은 - 당신의 테이블을 묘사 할 때 지름길을 사용하지 마십시오. 내가 잃어버린 td3은 어디에, 다음 td6, tdx3 ... 나는 당신도 잃어버린 것 같아요. 별칭을 좀더 현명하게 명명하면 잘못된 것을 얻고 6을 8 등으로 조합 할 기회가 줄어 듭니다.

그냥 sugestion : MySQL의에 제한이 없습니다

나의 내기가 인간의 오류에있을 것입니다 - 어딘가 논리가 실패가 가입 할 수 있습니다.