なぜサブクエリにグループ化するのかが問題を引き起こす理由

StackOverflow https://stackoverflow.com/questions/1577351

  •  21-09-2019
  •  | 
  •  

質問

次のサブクエリに2つのコメントアウト行を含めると、Sybase 12.5 ASEサーバーが結果を得るまで永遠にかかるようです。これらの2行がなければ、クエリはOKです。そのグループ化の何がそんなに悪いのですか?

select days_played.day_played, count(distinct days_played.user_id) as OLD_users
from days_played inner join days_received
on days_played.day_played = days_received.day_received
and days_played.user_id = days_received.user_id
where days_received.min_bulk_MT > days_played.min_MO
and days_played.user_id in

(select sgia.user_id 
from days_played as sgia
where sgia.day_played < days_played.day_played
--group by sgia.user_id 
--having sum(sgia.B_first_msg) = 0
)

group by days_played.day_played
役に立ちましたか?

解決 3

わかりました、私は問題がサブクエリーにユーザーIDを含めなければならなかったことを知りました: "where_played.user_id = sgia.user_id and sgia.day_played <days_played.day_played"

他のヒント

ShowPlanを使用して説明を表示して、クエリが何をするかを調べてください。

この場合、メインクエリの一部にすることで、サブクエリを排除できませんか?

次のようにクエリを書き直してみてください。

select days_played.day_played,
       count(distinct days_played.user_id) as OLD_users
  from days_played
 inner join days_received on days_played.day_played = days_received.day_received
                         and days_played.user_id = days_received.user_id
 where days_received.min_bulk_MT > days_played.min_MO
   and 0 = (select sum(sgia.B_first_msg)
              from days_played as sgia
             where sgia.user_id = days_played.user_id
               and sgia.day_played < days_played.day_played
            )
 group by days_played.day_played

これにより、パフォーマンスが向上するはずです...

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top