Sziasztok!
MySQL LOAD DATA INFILE-al egy nagy csv-t próbálok importálni adatbázisba. 500.000 sor, 93 oszlop és kb 600mb a fájlméret, InnoDB az AB motor (tudom, hogy MYISAM-al gyorsabb, de kötve vagyunk az innodb-hez).
Ez az import kódom:
$query = "LOAD DATA CONCURRENT LOCAL INFILE '$path'
INTO TABLE task_metas
CHARACTER SET utf8mb4
FIELDS TERMINATED BY '$delimiter'
OPTIONALLY ENCLOSED BY '$enclosed'
LINES TERMINATED BY '$lineending'
IGNORE 1 LINES
(@col1, @col2, @col3, @col4, @col5, @col6, @col7, @col8, @col9, @col10, @col11, @col12, @col13, @col14, @col15, @col16, @col17, @col18, @col19, @col20, @col21, @col22, @col23, @col24, @col25, @col26, @col27, @col28, @col29, @col30, @col31, @col32, @col33, @col34, @col35, @col36, @col37, @col38, @col39, @col40, @col41, @col42, @col43, @col44, @col45, @col46, @col47, @col48, @col49, @col50, @col51, @col52, @col53, @col54, @col55, @col56, @col57, @col58, @col59, @col60, @col61, @col62, @col63, @col64, @col65, @col66, @col67, @col68, @col69, @col70, @col71, @col72, @col73, @col74, @col75, @col76, @col77, @col78, @col79, @col80, @col81, @col82, @col83, @col84, @col85, @col86, @col87, @col88, @col89, @col90, @col91, @col92, @col93)
SET task_id=null, project_id=$project->id, full_comment=null, relevance=-1, note=null,
url=@col1, indexed=@col2, published=@col3, search_indexed=@col4, title_snippet=@col5, content_snippet=@col6, title=@col7, content=@col8, root_url=@col9, domain_url=@col10, host_url=@col11, parent_url=@col12, lang=@col13, porn_level=@col14, fluency_level=@col15, spam_level=@col16, sentiment=@col17, source_type=@col18, post_type=@col19, cluster_id=@col20, meta_cluster_id=@col21, tags_internal=@col22, tags_marking=@col23, tags_customer=@col24, entity_urls=@col25, images_url=@col26, images_width=@col27, images_height=@col28, images_legend=@col29, videos_url=@col30, videos_width=@col31, videos_height=@col32, videos_legend=@col33, pagemonitoring_sitemon_siteid=@col34, matched_profile=@col35, article_extended_attributes_facebook_shares=@col36, article_extended_attributes_facebook_likes=@col37, article_extended_attributes_twitter_retweets=@col38, article_extended_attributes_url_views=@col39, article_extended_attributes_pinterest_likes=@col40, article_extended_attributes_pinterest_pins=@col41, article_extended_attributes_pinterest_repins=@col42, article_extended_attributes_youtube_views=@col43, article_extended_attributes_youtube_likes=@col44, article_extended_attributes_youtube_dislikes=@col45, article_extended_attributes_instagram_likes=@col46, article_extended_attributes_twitter_shares=@col47, article_extended_attributes_num_comments=@col48, source_extended_attributes_alexa_pageviews=@col49, source_extended_attributes_facebook_followers=@col50, source_extended_attributes_twitter_followers=@col51, source_extended_attributes_instagram_followers=@col52, source_extended_attributes_pinterest_followers=@col53, extra_article_attributes_world_data_continent=@col54, extra_article_attributes_world_data_country=@col55, extra_article_attributes_world_data_country_code=@col56, extra_article_attributes_world_data_region=@col57, extra_article_attributes_world_data_city=@col58, extra_article_attributes_world_data_longitude=@col59, extra_article_attributes_world_data_latitude=@col60, extra_author_attributes_id=@col61, extra_author_attributes_type=@col62, extra_author_attributes_name=@col63, extra_author_attributes_birthdate_date=@col64, extra_author_attributes_birthdate_resolution=@col65, extra_author_attributes_gender=@col66, extra_author_attributes_image_url=@col67, extra_author_attributes_short_name=@col68, extra_author_attributes_url=@col69, extra_author_attributes_world_data_continent=@col70, extra_author_attributes_world_data_country=@col71, extra_author_attributes_world_data_country_code=@col72, extra_author_attributes_world_data_region=@col73, extra_author_attributes_world_data_city=@col74, extra_author_attributes_world_data_longitude=@col75, extra_author_attributes_world_data_latitude=@col76, extra_source_attributes_world_data_continent=@col77, extra_source_attributes_world_data_country=@col78, extra_source_attributes_world_data_country_code=@col79, extra_source_attributes_world_data_region=@col80, extra_source_attributes_world_data_city=@col81, extra_source_attributes_world_data_longitude=@col82, extra_source_attributes_world_data_latitude=@col83, engagement=@col84, reach=@col85, provider=@col86, generator_type=@col87, source_extended_attributes_alexa_unique_visitors=@col88, article_extended_attributes_twitter_likes=@col89, extra_author_attributes_description=@col90, article_extended_attributes_linkedin_shares=@col91, extra_source_attributes_name=@col92, word_count=@col93,
created_at=NOW(), updated_at=NOW()";
A query futtatása után visszakapok egy számot arról,hogy mennyi sor került be adatbázisba, ami eddig mindig helyes volt.
A probléma az, hogy amikor megnézem az adatbázist, sokszor nem annyi sort pakol be rögtön, mint amenynit visszaad a query. 519.000-nek kellene lennie, de pl. a legutóbbi importnál csak 463.000 volt. Ennél furcsább, hogy ha pár mp múlva újra lekérem az ab táblát, már több sort mutat benne - kb 1000-esével növekedik cca 30mp-enként.
Tehát nagyjából egy 40p alatt felmegy a tényleges 519.000 sorra az inserted sorok száma.
Ez miért van? Olyan, mintha utólag aszinkron pakolná be a sorokat. Ki lehet ezt valahogy kerülni?
+ update
Még az is furcsa, hogy az importált sorok lekérésénél, amikor még fut ez az aszinkron 'utóimport(?)' elszáll a szerver memóriatúllépés miatt, de csak ha azokat a sorokat kérem le. Ha egy korábban futtatott import sorait kérem le, no problemo.
Olyan lehet, hogy a MYSQL szerver lecache-elte azokat a sorokat amire már nem volt elég memóriája és szépen üríti? Szintén szuper lenne ide egy megoldás
[ Szerkesztve ]
https://heureka-kreativ.hu