-1

たぶんこれは基本的な質問ですが、答えることができませんでした、そしてあなたの助けをいただければ幸いです:)

MySQLには次のテーブルがあります。

create table anotation
    ( 
        chromosome enum
            (
                'Chr1',
                'Chr2',
                'Chr3',
                'Chr4',
                'Chr5',
                'ChrC',
                'ChrM'
            ), 
        version varchar(10),
        type enum
            (
                'CDS',
                'chromosome',
                'exon',
                'five_prime_UTR',
                'gene',
                'mRNA',
                'mRNA_TE_gene',
                'miRNA',
                'ncRNA',
                'protein',
                'pseudogene',
                'pseudogenic_exon',
                'pseudogenic_transcript',
                'rRNA',
                'snRNA',
                'snoRNA',
                'tRNA',
                'three_prime_UTR',
                'transposable_element_gene'
            ), 
        strand enum
            (
                 '+',
                 '-'
            ), 
        phase tinyint, 
        atrributes text
    );`

そして、それは約600,000の値を持っており、私は次のクエリを実行しています。

select distinct
            anot_1.chromosome,
            anot_1.start,
            anot_1.end,
            anot_1.atrributes 
    from 
            anotation anot_1,
            anotation anot_2 
    where
            anot_1.type='CDS'
        and
            anot_2.type='protein'
        and 
            anot_1.chromosome!='ChrM'
        and
            anot_1.chromosome!='ChrC'
        and
            anot_1.chromosome=anot_2.chromosome
        and 
        (
            (
                anot_2.start=anot_1.start
            and
                anot_1.end!=anot_2.end
            and
                anot_2.strand='+'
            ) 
        or 
            (
                anot_2.start!=anot_1.start
            and
                anot_1.end=anot_2.end
            and
                anot_2.strand='-'
            )
        );

そして、実際には終了するのに長い時間がかかりますが、クエリを実行すると(同じものですが、ORから条件の1つを削除します)、ほぼ瞬時に実行されます。

select distinct
            anot_1.chromosome,
            anot_1.start,
            anot_1.end,
            anot_1.atrributes
    from
            anotation anot_1, 
            anotation anot_2
    where
            anot_1.type='CDS'
        and 
            anot_2.type='protein'
        and 
            anot_1.chromosome!='ChrM'
        and
            anot_1.chromosome!='ChrC'
        and
            anot_1.chromosome=anot_2.chromosome
        and
            anot_2.start=anot_1.start
        and
            anot_1.end!=anot_2.end
        and 
            anot_2.strand='+';`

誰もが何が起こっているのかについて何か考えを持っています、もしそうなら、どうすればそれを解決できますか?ありがとうございました!!!

4

2 に答える 2

0

これは解決策ではありません(インデックスに関する上記のコメントに同意します)が、JOINにORがある現在のSQLではなく、左外部結合のペアを使用するようにSQLを変更しました。

これがパフォーマンスに大きな違いをもたらすとは思いませんが、あなたや他の人がクエリが何をしているかを理解するのに役立つかもしれません:-

SELECT distinct anot_1.chromosome, anot_1.start, anot_1.end, anot_1.atrributes 
FROM anotation anot_1,
LEFT OUTER JOIN anotation anot_2 ON anot_1.chromosome = anot_2.chromosome AND anot_1.start = anot_2.start AND anot_1.end != anot_2.end AND anot_2.strAND = '+' AND anot_2.type='protein'
LEFT OUTER JOIN anotation anot_3 ON anot_1.chromosome = anot_3.chromosome AND anot_1.end = anot_3.end AND anot_1.start != anot_3.start AND anot_3.strAND = '+' AND anot_3.type='protein'
WHERE anot_1.type = 'CDS'  
AND anot_1.chromosome != 'ChrM' 
AND anot_1.chromosome != 'ChrC' 
AND (anot_2.chromosome IS NOT NULL
OR anot_3.chromosome IS NOT NULL)
于 2012-11-22T11:28:54.040 に答える
0

一般的にクエリをサニタイズし、それらを分解してユニオンを実行することから始めます

select
            CDS.chromosome,
            CDS.start,
            CDS.end,
            CDS.atrributes 
    from
            (
            select
                        a.chromosome,
                        a.start,
                        a.end,
                        a.attribures,
                from
                        anotation a,
                where
                        a.type='CDS'
                    and
                        not a.chromosome IN ('ChrM', 'ChrC')
            ) CDS
        join
            (
            select
                        a.strand,
                from
                        anotation a,
                where
                        a.type='protien'
            ) Protien
                on 
                        CDS.chromosome = Protien.chromosome
                   and
                        CDS.start = Protien.start
                   and
                        CDS.end != Protien.end 
where
            Protien.strand = '+'
union
    select
            CDS.chromosome,
            CDS.start,
            CDS.end,
            CDS.atrributes 
    from
            (
            select
                        a.chromosome,
                        a.start,
                        a.end,
                        a.attribures,
                from
                        anotation a,
                where
                        a.type='CDS'
                    and
                        not a.chromosome IN ('ChrM', 'ChrC')
            ) CDS
        join
            (
            select
                        a.strand,
                from
                        anotation a,
                where
                        a.type='protien'
            ) Protien
                on 
                        CDS.chromosome = Protien.chromosome
                   and
                        CDS.start != Protien.start
                   and
                        CDS.end = Protien.end 
where
            Protien.strand = '-'
于 2012-11-22T11:40:05.517 に答える