免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4106 | 回复: 5
打印 上一主题 下一主题

超级长SQL语句优化 欢迎拍砖 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-01-05 18:20 |只看该作者 |倒序浏览
一同事写的,现在我来优化,大家都有什么好主意

SELECT hotelid,hotelkey,hotelname,price,map_lat,map_lng,count_image,count_comment,price,comment,imageid
                        FROM
                                listdo_hotel_main
                        WHERE
                                hotelid IN (520513,520514,520515,520516,520517,520518,520519,520520,520522,520523,520524,520525,5205
26,520527,520528,520529,520530,520533,520534,520537,520538,520539,520541,520542,520543,520546,520548,520551,520552,520554,520555,520
558,520559,520560,520587,520595,520596,520597,520605,520609,520610,520611,520613,520623,520635,520636,520642,520643,520645,520646,52
0647,532578,532579,532581,532584,532589,532603,53
2645,532648,532657,532661,532662,532663,532665,532666,532667,532668,532669,532707,532712,532714,532715,532716,532717,532718,532719,5
32720,532723,532743,532746,532754,532785,532786,532787,532788,532789,532790,532791,532792,532793,532794,532795,532796,532799,532800,
532801,532802,532804,532805,532807,532808,532809,532810,532811,532812,532813,532814,532815,532816,532817,532819,532821,532824,532825
,532826,532827,532828,532829,532830,532832,532833,532834,532835,532836,532837,532842,532843,532844,532846,532849,532855,532857,53285
9,532864,532872,532880,532881,532883,532884,532888,532889,532892,532896,532898,532904,532925,532927,532936,532939,532946,532950,5329
52,532953,532963,532964,532965,532968,532969,532972,532973,532975,533007,533008,533009,533011,533013,533017,533020,533021,533023,533
025,533027,533029,533030,533031,533032,533034,533035,533036,533037,533038,533039,533042,533044,533048,533054,533070,533079,533080,53
3082,533085,533091,533095,533097,533100,533107,533108,533112,533113,533116,533117,533118,533119,533122,533123,533125,533126,533127,5
33128,533129,533130,533131,533132,533135,533136,533137,533139,533140,533186,533187,533188,533189,533192,533193,533194,533195,533196,
533197,533199,533200,533202,533203,533205,533207,533208,533210,533211,533212,533213,533214,533215,533216,533218,533219,533220,533222
,533224,533225,533229,533234,533235,533237,533238,533240,533241,533243,533244,533245,533250,533251,533252,533254,533255,533259,53326
0,533261,533264,533265,533267,533268,533269,533270,533273,533279,533285,533286,533292,533293,533294,533295,533330,533334,533339,5333
42,533344,533358,533370,533371,533373,533374,533379,533388,533406,533409,533411,533412,533414,533415,533416,533417,533420,533421,533
422,533425,533426,533427,533428,533429,533430,533433,533434,533436,533437,533438,533439,533440,533441,533442,533444,533448,533449,53
3450,533451,533456,533458,533460,533464,533466,533467,533468,533469,533473,533475,533476,533525,533526,533535,533536,533559,533561,5
33562,533563,533564,533567,533569,533577,533580,533582,533592,533594,533595,533597,533598,533600,533612,533615,533620,533621,533622,
533625,533628,533629,533632,533633,533634,533635,533636,533637,533638,533639,533640,533642,533643,533644,533645,533647,533648,533649
,533650,533651,533652,533653,533656,533658,533659,533660,533661,533663,533664,533666,533667,533668,533669,533671,533672,533674,53367
5,533676,533677,533678,533679,533680,533681,533682,533683,533684,533685,533686,533689,533690,533691,533692,533693,533694,533695,5336
98,533701,545730,545732,545733,545735,545739,545741,545751,54
5759,545761,545762,545763,545764,545768,545769,545772,545776,545781,545785,545787,545793,545797,545800,545802,545804,545807,545809,5
45811,545812,545816,545819,545830,545838,545842,545844,545846,545848,545849,545850,545852,545855,545856,545858,545863,545866,545872,
545877,545883,545889,545897,545898,545900,545906,545907,545908,545910,545914,545916,545922,545925,545943,545949,545959,545960,545961
,545962,545963,545970,545971,557958,557963,557964,557975,557977,557985,557989,557990,558003,558010,
558011,558012,558016,558038,558040,558041,558042,558043,558047,558050,558054,558056,558078,558097,558100,558124,558142,558144,558151
,558155,558157,558161,558162,558164,558167,558170,558171,558172,558174,558178,558182,558183,558184,558185,558186,558188,558189,55819
0,558191,558192,558193,558205,558208,561772,561773,561814,561818,561834,561835,561836,561982,562002,5
62012,562027,562035,562056,562108,562114,562142,562145,562167,562169,562261,562274,562285,562292,562299,562384,562396,562406,562407,
562448,562485,562670,562721,572207,572208,572211,572217,572218,572220,572221,572222,572223,
572226,572227,572229,572233,572235,572239,572240,572241,572242,572243,572247,572248,572249,572252,572253,572254,572262,572263,572265
,572266,572267,572268,572269,572270,572271,572272,572275,572276,572277,572278,572279,572280,572281,572282,572283,572284,572287,57229
0,572292,572294,572297,572298,572299,572301,572303,572305,572306,572307,572308,572310,572312,572315,572316,572319,572320,572321,5723
22,572324,572325,572326,572328,572330,572331,572332,572333,572334,572338,572339,572342,572343,572345,572351,572353,572354,572355,572
357,597200,597201,597202,597204,597205,597206,597207,597208,597209,597211,597212,5972
13,597214,597216,597217,597218,597219,597220,597221,597222,597223,597224,597225,597227,597230,597231,597235,597236,597237,597240,597
242,597243,597244,597245,597246,597247,597248,597249,597251,597252,597253,597254,597255,597256,597257,597258,597259,597260,597261,59
7263,597265,597266,597267,597268,597269,597270,597271,597272,597273,597274,597277,597281,597282,597283,597285,597286,597287,597288,5
97290,597291,597292,597293,597295,597296,597297,597298,597299,597300,597305,597306,597307,597308,597309,597311,597312,597313,597314,
597315,597316,597318,597320,597321,597322,597323,597324,597325,597327,597328,597329,597330,597332,597333,597334,597335,597336,597338
,597339,597340,597341,597342,597343,597344,597346,597347,597348,597349,597350,597351,597355,597357,597359,597360,597361,597362,59736
4,597365,597366,597367,597368,597371,597372,597373,597374,597375,597376,597377,597378,597379,597380,597382,597383,597384,597386,5973
87,597388,597389,597390,597392,597393,597394,597395,597396,597397,597399,597400,597401,597403,597404,597405,597408,597412,597413,597
414,597416,597417,597419,597420,597421,597422,597423,597425,597428,597429,597430,597431,597432,597434,597435,597436,597437,597438,59
7439,597440,597441,597442,597443,597445,597446,597447,597448,597449,597450,597451,597455,597456,597457,597458,597460,597462,597463,5
97464,597465,597466,597467,597468,597469,597470,597472,597475,597477,597478,597479,597480,597481,597482,597483,597484,597485,597486,
597487,597488,597490,597491,597492,597493,597494,597495,597497,597498,597499,597500,597501,597504,597506,597509,597510,597511,597512
,597513,597514,597515,597516,597518,597519,597521,597522,597523,597524,597525,597529,597530,597531,597532,597534,597535,597536,59753
7,597540,597541,597542,597543,597544,597545,597546,597547,597548,597550,597551,597552,597553,597555,597556,597557,597558,597560,5975
61,597563,597567,597568,597569,597570,597572,597573,597574,597576,597578,597579,597580,597581,597582,597583,597585,597586,597587,597
588,597590,597591,597593,597594,597595,597596,597599,597600,597603,597605,597607,597608,597610,597614,597616,597618,597619,597620,59
7621,597622,597623,597624,597625,597626,597627,597628,597629,597630,597631,597633,597634,597635,597636,597638,597639,597640,597641,5
97642,597643,597644,597646,597647,597648,597650,597651,597652,597653,597657,597660,597662,597663,597665,597666,597810,597977,597997,
598011,598026,598030,598035,598042,598052,598068,598105,598237,598242,598347,598453,598469,598477,598481,598482,598483,598484,598485
,598486,598487,598488,598491,598492,598493,598494,598496,598497,598498,598499,598500,598501,598502,598505,598506,598507,598509,59851
1,598512,598513,598516,598517,598518,598519,598521,598522,598523,598525,598527,598529,598530,598531,598532,598533,598534,598535,5985
46,598549,598550,598552,598554,598556,598557,598559,598560,598562,598563,598564,598565,598566,598567,598570,599119,599254,599938,599
940,599941,599943,600621,600624,600628,600629,600904,601308,601309,601310,601312,601315,601318,601322,601939,601999,602002,602681,60
2687,602712,602738,602742,602761,602764,602765,602766,602771,602772,602780,602791,602792,602793,602797,602799,602803,602805,602857,6
03323,603326,603329,603333,603343,603346,603357,603370,603371,603377,603378,603386,603390,603397,603408,603414,603419,603428,603435,
603438,603440,603442,603447,603457,603458,603459,603470,603471,603473,603475,603483,603484,603501,603508,603509,603515,603516,603532
,603539,603542,603543,603557,603558,603562,603564,603567,603568,603569,603573,603577,603580,603584,603585,603586,603587,603590,60359
2,603593,603594,603595,603597,603598,603600,603601,603603,603604,603606,603607,603609,603617,603618,603619,603627,603628,603636,6036
37,603645,603647,603648,603655,603659,603663,603671,603684,603695,603699,603710,603716,603720,603722,603723,603725,603728,603729,603
731,603732,603734,603738,603739,603746,603752,603756,603758,603760,603761,603762,603764,603774,603775,603783,603788,603789,603791,60
3794,603797,603799,603802,603804,603812,603817,603818,603821,603822,603825,603826,603827,603828,603829,603830,603831,603832,603833,6
03835,603836,603837,603838,603840,603846,603855,603857,603864,603865,603867,603868,603872,603875,603877,603879,603880,603881,603883,
603884,603886,603889,603916,603917,603919,603920,603922,603923,603924,603925,603928,603929,604429,604558,604559,604561,605236,605237
,605918,605973,606231,606606,606607,606611,607294,607295,607851,607852,607853,608531,608555,608599,608764,608766,608767,608785,60879
8,608852,608857,608897,608901,608908,608909,608943,608959,608992,609015,609023,609030,609033,609038,609043,609082,609084,609092,6091
03,609140,609142,609149,609150,609155,609174,609190,609192,609211,609212,609213,609214,609221,609222,609223,609224,609227,609228,609
230,609232,609233,609235,609236,609238,609240,609242,609243,609245,609248,609249,609250,609251,609253,609260,609262,609265,609266,60
9269,609270,609272,609277,609278,609281,609283,609284,609290,609291,609292,609295,609304,609305,609306,609309,609312,609313,609314,6
09318,609319,609320,609321,609325,609327,609328,609330,609334,609338,609343,609347,609351,609352,609361,609362,609368,609379,609388,
609389,609395,609399,609403,609408,609413,609414,609415,609418,609419,609420,609421,609423,609424,609428,609651,609656,609657,609658
,609660,609661,609662,609666,609669,609674,609675,609676,609679,609681,609688,609691,609692,609693,609793,610000,610001,610003,61000
5,610006,610008,610009,610010,610011,610012,611244,611735,611751,611827,611831,611848,611851,611852,611892,611893,611903,611941,6119
43,611959,611969,611977,611978,612003,612022,612023,612028,612035,612085,612128,612132,612162,612202,612214,612220,612224,612227,612
229,612253,612292,612297,612305,612306,612345,612354,612355,612356,612369,612427,612439,612443,612470,612497,612511,612574,612596,61
2615,612694,612775,612789,612816,612867,612873,612885,612891,612912,612913,612970,612986,613011,613029,613036,613125,613314,613383,6
13433,613687,614037,614040,614045,614046,614047,614051,614055,614058,614061,614062,614063,614065,614068,614070,614071,614080,614094,
614095,614103,614104,614113,614117,614123,614131,614132,614135,614136,614158,614165,614166,614207,614210,614245,614248,614280,614335
,614342,614355,614356,614360,614363,614542,614793,614845,614908,614909,614957,615084,615160,615169,615220,615249,615294,615355,61543
2,615479,615639,615696,615705,615847,615855,616057,616073,616268,616379,616416,616463,616546,616558,616593,616635,616747,617001,6170
06,617101,617248,617287,617410,617513,617598,617654,617761,617789,617810,617825,617852,618099,618175,618486,618487,618490,618495,618
684,618875,618979,619014,619036,619114,619123,619184,619197,619254,619266,619330,619414,619467,619509,619530,619535,619568,619599,61
9738,619767,619807,619823,619961,620039,620123,620171,620201,620230,620249,620294,620469,620484,620489,620580,620587,620591,620623,6
20673,620701,620834,620853,620886,621075,621150,621235,621238,621255,621310,621335,621469,621502,621529,621628,621642,621708,621853,
621858,621926,622020,622061,622207,622239,622272,622311,622417,622458,622593,622763,622976,622985,623027,623033,623045,623046,623098
,623251,623350,623364,623388,623432,623481,623483,623619,623853,623900,623989,623999,624025,624076,624263,624433,624553,624592,62460
8,624909,624917,624959,625116,625225,625381,625735,625758,625806,625812,625820,625887,625959,625991,626050,626053,626085,626122,6261
89,626272,626279,626281,626283,626295,626300,626326,626332,626335,626357,626370,626375,626376,626421,626475,626481,626488,626529,626
533,626559,626568,626580,626633,626634,626647,626662,626723,626726,626737,626772,626792,626798,626800,626808,626826,626853,626878,62
6885,626924,626935,626952,626976,626987,626998,627014,627048,627060,627075,627077,627080,627091,627104,627127,627139,627140,627160,6
27164,627191,627194,627197,627225,627251,627305,627317,627333,627334,627336,627339,627358,627373,627379,627416,627427,627430,627433,
627436,627451,627453,627457,627472,627478,627495,627498,627534,627539,627556,627557,627562,627568,627570,627581,627608,627625,627628
,627671,627679,627719,627730,627733,627747,627768,627774,627784,627806,627807,627851,627860,627880,627883,627892,627900,627917,62793
4,627952,627973,627984,627993,628000,628017,628030,628067,628132,628133,628136,628143,628170,628184,628186,628202,628224,628228,6282
34,628261,628271,628272,628273,628277,628291,628295,628299,628318,628321,628325,628328,628352,628355,628368,628369,628373,628374,628
408,628449,628467,628503,628506,628521,628547,628561,628562,628594,628596,628614,628622,628627,628632,628661,628662,628664,628666,62
8683,628705,628714,628723,628727,628729,628753,628764,628783,628808,628812,628839,628851,628859,628872,628873,628874,628875,628877,6
28889,628904,628905,628915,628916,628938,628939,628941,628950,628951,628954,628959,628984,628986,628987,628993,629007,629010,629021,
629028,629040,629053,629058,629060,629063,629071,629087,629094,629099,629101,629103,629108,629112,629121,629176,629197,629227,629244
,629253,629296,629345,629369,629392,629412,629418,629424,629428,629433,629466,629468,629487,629488,629505,629507,629542,629556,62957
4,629641,629666,629667,629691,629693,629702,629778,629783,629784,629785,629791,629797,629801,629802,629860,629877,629881,629887,6298
89,629893,629915,629919,629931,629938,629951,629982,630040,630053,630063,630095,630097,630106,630109,630121,630166,630178,630179,630
187,630190,630191,630193,630211,630218,630235,630240,630242,630266,630269,630270,630272,630328,630329,630332,630337,630346,630394,63
0400,630406,630411,630413,630424,630506,630555,630557,630558,630642,630643,630735,630749,630750,630775,630792,630794,630855,630867,6
30879,630881,630893,630894,630905,630917,630918,630960,630961,630964,630971,630979,630981,630983,630993,630996,631001,631005,631008,
631017,631042,631044,631067,631070,631171,631199,631324,631333,631412,631415,631416,631417,631418,631419,631420,631531,631547,631601
,631802,631843,631854,631856,631863,631884,631912,631916,631921,631955,632001,632007,632021,632022,632042,632046,632049,632052,63205
4,632069,632070,632116,632128,632143,632144,632163,632173,632206,632216,632217,632223,632226,632245,632267,632276,632278,632281,6322
82,632283,632289,632290,632294,632302,632307,632309,632327,632331,632339,632344,632345,632354,632355,632356,632357,632361,632362,632
367,632370,632371,632373,632375,632376,632377,632379,632380,632381,632382,632383,632385,632386,632387,632388,632389,632391,632392,63
2393,632394,632395,632396,632398,632401,632403,632404,632406,632407,632408,632410,632411,632412,632413,632416,632417,632420,632423,6
32424,632430,632431,632437,632438,632446,632449,632450,632452,632453,632454,632456,632466,632467,632472,632474,632475,632477,632478,
632479,632481,632483,632498,632499,632500,632501,632502,632505,632506,632507,632508,632509,632510,632511,632512,632513,632514,632515
,632516,632517,632518,632520,632521,632522,632523,632525,632526,632529,632530,632536,632542,632543,632544,632545,632546,632548,63255
2,632553,632557,632559,632564,632565,632566,632568,632573,632574,632575,632576,632581,632584,632587,632588,632590,632592,632594,6325
97,632598,632599,632601,632602,632603,632604,632608,632611,632612,632615,632616,632617,632622,632623,632629,632631,632633,632635,632
639,632643,632644,632646,632651,632659,632666,632667,632668,632670,632671,632672,632676,632679,632685,632686,632688,632689,632690,63
2693,632696,632698,632708,632709,632710,632711,632712,632713,632714,632715,632716,632717,632719,632720,632722,632723,632724,632725,6
32726,632727,632730,632733,632734,632739,632743,632744,632745,632746,632747,632749,632750,632751,632752,632753,632754,632755,632756,
632763,632764,632765,632767,632768,632769,632772,632774,632778,632779,632781,632786,632796,632797,632799,632806,632807,632808,632809
,632812,632813,632816,632817,632818,632819,632821,632822,632826,632843,632851,632857,632865,632866,632867,632868,632869,632874,63287
8,632879,632882,632887,632888,632889,632893,632894,632896,632899,632914,632915,632916,632918,632927,632928,632930,632932,632934,6329
38,632939,632940,632941,632944,632946,632950,632953,632954,632960,632961,632962,632964,632967,632968,632983,632984,632985,632990,632
992,632993,632996,632998,633000,633001,633005,633006,633009,633013,633014,633015,633016,633021,633026,633027,633028,633029,633030,63
3031,633032,633033,633036,633037,633039,633045,633047,633048,633052,633056,633061,633066,633071,633075,633080,633099,633102,633103,6
33106,633107,633109,633110,633111,633112,633113,633114,633115,633116,633118,633122,633123,633126,633128,633130,633135,633140,633152,
633153,633156,633157,633161,633165,633172,633173,633174,633175,633177,633178,633179,633188,633189,633190,633191,633193,633194,633195
,633198,633201,633202,633204,633207,633212,633213,633214,633215,633216,633217,633218,633219,633220,633221,633223,633224,633225,63322
6,633227,633228,633229,633230,633231,633251,633286,633287,633288,633298,633299,633308,633310,633311,633313,633318,633319,633321,6333
24,633326,633327,633328,633330,633331,633333,633334,633336,633337,633338,633339,633342,633343,633344,633346,633347,633348,633349,633
350,633352,633353,633354,633355,633356,633357,633361,633362,633363,633364,633374,633375,633377,633379,633383,633384,633397,633406,63
3407,633417,633422,633425,633430,633431,633432,633434,633441,633443,633444,633447,633450,633464,633466,633467,633471,633475,633476,6
33481,633485,633487,633489,633491,633494,633498,633501,633503,633505,633506,633507,633511,633513,633514,633521,633522,633525,633526,
633531,633532,633533,633534,633541,633547,633549,633553,633554,633557,633562,633563,633565,633571,633578,633580,633581,633582,633583
,633585,633586,633587,633588,633590,633591,633597,633598,633599,633600,633601,633616,633620,633625,633632,633635,633637,633639,63364
1,633643,633646,633656,633658,633661,633662,633664,633665,633667,633669,633670,633671,633672,633674,633676,633677,633679,633680,6336
83,633684,633685,633690,633695,633704,633705,633707,633708,633713,633720,633721,633722,633723,633724,633726,633727,633731,633732,633
734,633737,633740,633743)
                        ORDER BY
                                orderid,hotelrank DESC
                        LIMIT
                                0,50;

论坛徽章:
1
白银圣斗士
日期:2015-11-23 08:33:04
2 [报告]
发表于 2010-01-05 18:29 |只看该作者
in 里的数据放入临时表

论坛徽章:
0
3 [报告]
发表于 2010-01-05 18:54 |只看该作者
在执行的时候系统会自己放进临时表吧?

论坛徽章:
381
CU十二周年纪念徽章
日期:2014-01-04 22:46:58CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52CU大牛徽章
日期:2013-03-14 14:08:55CU大牛徽章
日期:2013-04-17 11:17:19CU大牛徽章
日期:2013-04-17 11:17:32CU大牛徽章
日期:2013-04-17 11:17:37CU大牛徽章
日期:2013-04-17 11:17:42CU大牛徽章
日期:2013-04-17 11:17:47CU大牛徽章
日期:2013-04-17 11:17:52CU大牛徽章
日期:2013-04-17 11:17:56
4 [报告]
发表于 2010-01-05 20:53 |只看该作者
in子句里面的条件貌似一点规律也没有
这样的条件也太Bt了

论坛徽章:
0
5 [报告]
发表于 2010-01-05 21:11 |只看该作者
in中的变量列表放入到临时表,做一个表连接。

论坛徽章:
8
综合交流区版块每周发帖之星
日期:2015-12-02 15:03:53数据库技术版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每日发帖之星
日期:2015-09-14 06:20:00金牛座
日期:2014-10-10 11:23:34CU十二周年纪念徽章
日期:2013-10-24 15:41:34酉鸡
日期:2013-10-19 10:17:1315-16赛季CBA联赛之北京
日期:2017-03-06 15:12:44
6 [报告]
发表于 2010-01-06 18:26 |只看该作者
in的数据很BT
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP