I have a XML file (50GB, 900M lines approx.), in which I wish to gather some data. I have calculated that these 900M lines in the XML-file will result in about 8M rows that are to be stored in the database. How should my approach be?
First, I thought of using a PHP script. This script should go through the whole file with XMLReader, gather the data for one row in an array, insert the data from that array in the database, delete that array (and thereby release memory) and so on (new array with data, insert in database, delete array etc.)
I was then told that this is an OK idea - however pretty dumb. This would take AGES and I would have some limits. Instead, I should think about importing the XML file directly to MySQL and then remove the unwanted data afterwards with SQL scripting. Is this the optimal approach? If so, could anyone elaborate on how this should be done?
Or is there an other/better approach?
EDIT (Sample from the XML file):
<?xml version="1.0" encoding="UTF-8"?>
<ns:ESStatistikListeModtag_I xmlns:ns="">
<ns:StatistikSamling>
<ns:Statistik>
<ns:KoeretoejIdent>1026503230510888</ns:KoeretoejIdent>
<ns:KoeretoejArtNummer>3</ns:KoeretoejArtNummer>
<ns:KoeretoejArtNavn>Varebil</ns:KoeretoejArtNavn>
<ns:KoeretoejAnvendelseStruktur>
<ns:KoeretoejAnvendelseNummer>40</ns:KoeretoejAnvendelseNummer>
<ns:KoeretoejAnvendelseNavn>Godstransport erhverv</ns:KoeretoejAnvendelseNavn>
</ns:KoeretoejAnvendelseStruktur>
<ns:RegistreringNummerNummer>TX90281</ns:RegistreringNummerNummer>
<ns:RegistreringNummerUdloebDato>2010-11-19+01:00</ns:RegistreringNummerUdloebDato>
<ns:KoeretoejOplysningGrundStruktur>
<ns:KoeretoejOplysningOprettetUdFra>Typeattest</ns:KoeretoejOplysningOprettetUdFra>
<ns:KoeretoejOplysningStatus>Eksporteret</ns:KoeretoejOplysningStatus>
<ns:KoeretoejOplysningStatusDato>2011-04-06T00:00:00.000+02:00</ns:KoeretoejOplysningStatusDato>
<ns:KoeretoejOplysningFoersteRegistreringDato>2005-11-04+01:00</ns:KoeretoejOplysningFoersteRegistreringDato>
<ns:KoeretoejOplysningStelNummer>JTDKC283800028896</ns:KoeretoejOplysningStelNummer>
<ns:KoeretoejOplysningTotalVaegt>1525</ns:KoeretoejOplysningTotalVaegt>
<ns:KoeretoejOplysningEgenVaegt>1025</ns:KoeretoejOplysningEgenVaegt>
<ns:KoeretoejOplysningTekniskTotalVaegt>1525</ns:KoeretoejOplysningTekniskTotalVaegt>
<ns:KoeretoejOplysningAkselAntal>2</ns:KoeretoejOplysningAkselAntal>
<ns:KoeretoejOplysningStoersteAkselTryk>825</ns:KoeretoejOplysningStoersteAkselTryk>
<ns:KoeretoejOplysningTilkoblingMulighed>false</ns:KoeretoejOplysningTilkoblingMulighed>
<ns:KoeretoejOplysningBlokering>false</ns:KoeretoejOplysningBlokering>
<ns:KoeretoejOplysningTypeAnmeldelseNummer>A10253</ns:KoeretoejOplysningTypeAnmeldelseNummer>
<ns:KoeretoejOplysningKommentar>DMR Konvertering</ns:KoeretoejOplysningKommentar>
<ns:KoeretoejOplysningAntalGear>5</ns:KoeretoejOplysningAntalGear>
<ns:KoeretoejBetegnelseStruktur>
<ns:KoeretoejMaerkeTypeNummer>10265</ns:KoeretoejMaerkeTypeNummer>
<ns:KoeretoejMaerkeTypeNavn>TOYOTA</ns:KoeretoejMaerkeTypeNavn>
<ns:Model>
<ns:KoeretoejModelTypeNummer>10265030</ns:KoeretoejModelTypeNummer>
<ns:KoeretoejModelTypeNavn>YARIS</ns:KoeretoejModelTypeNavn>
</ns:Model>
<ns:Variant>
<ns:KoeretoejVariantTypeNummer>1026503013</ns:KoeretoejVariantTypeNummer>
<ns:KoeretoejVariantTypeNavn>1,4 VERSO TD</ns:KoeretoejVariantTypeNavn>
</ns:Variant>
<ns:Type>
<ns:KoeretoejTypeTypeNummer>10265030130000001</ns:KoeretoejTypeTypeNummer>
<ns:KoeretoejTypeTypeNavn>UOPLYST</ns:KoeretoejTypeTypeNavn>
</ns:Type>
</ns:KoeretoejBetegnelseStruktur>
<ns:KoeretoejFarveStruktur>
<ns:FarveTypeStruktur>
<ns:FarveTypeNummer>1</ns:FarveTypeNummer>
<ns:FarveTypeNavn>Ukendt</ns:FarveTypeNavn>
</ns:FarveTypeStruktur>
</ns:KoeretoejFarveStruktur>
<ns:KarrosseriTypeStruktur/>
<ns:KoeretoejSupplerendeKarrosseriSamlingStruktur>
<ns:KoeretoejSupplerendeKarrosseriSamling>
<ns:KoeretoejSupplerendeKarrosseriTypeStruktur>
<ns:SupplerendeKarrosseriTypeNummer>61</ns:SupplerendeKarrosseriTypeNummer>
<ns:SupplerendeKarrosseriTypeNavn>Lukket kasse</ns:SupplerendeKarrosseriTypeNavn>
</ns:KoeretoejSupplerendeKarrosseriTypeStruktur>
</ns:KoeretoejSupplerendeKarrosseriSamling>
</ns:KoeretoejSupplerendeKarrosseriSamlingStruktur>
<ns:KoeretoejNormStruktur>
<ns:NormTypeStruktur>
<ns:NormTypeNummer>24</ns:NormTypeNummer>
<ns:NormTypeNavn>År 2000 miljønorm</ns:NormTypeNavn>
</ns:NormTypeStruktur>
</ns:KoeretoejNormStruktur>
<ns:KoeretoejMiljoeOplysningStruktur>
<ns:KoeretoejMiljoeOplysningPartikelFilter>false</ns:KoeretoejMiljoeOplysningPartikelFilter>
</ns:KoeretoejMiljoeOplysningStruktur>
<ns:KoeretoejMotorStruktur>
<ns:KoeretoejMotorCylinderAntal>4</ns:KoeretoejMotorCylinderAntal>
<ns:KoeretoejMotorSlagVolumen>1364.0</ns:KoeretoejMotorSlagVolumen>
<ns:KoeretoejMotorStoersteEffekt>102.0</ns:KoeretoejMotorStoersteEffekt>
<ns:DrivkraftTypeStruktur>
<ns:DrivkraftTypeNummer>2</ns:DrivkraftTypeNummer>
<ns:DrivkraftTypeNavn>Diesel</ns:DrivkraftTypeNavn>
</ns:DrivkraftTypeStruktur>
</ns:KoeretoejMotorStruktur>
</ns:KoeretoejOplysningGrundStruktur>
<ns:EjerBrugerSamling>
<ns:EjerBruger>
<ns:EjerBrugerForholdGrundStruktur>
<ns:EjerBrugerForholdForhold>Bruger</ns:EjerBrugerForholdForhold>
<ns:EjerBrugerForholdPrimaer>false</ns:EjerBrugerForholdPrimaer>
</ns:EjerBrugerForholdGrundStruktur>
<ns:PersonKoen>3</ns:PersonKoen>
</ns:EjerBruger>
<ns:EjerBruger>
<ns:EjerBrugerForholdGrundStruktur>
<ns:EjerBrugerForholdForhold>Ejer</ns:EjerBrugerForholdForhold>
<ns:EjerBrugerForholdPrimaer>false</ns:EjerBrugerForholdPrimaer>
</ns:EjerBrugerForholdGrundStruktur>
<ns:PersonKoen>3</ns:PersonKoen>
</ns:EjerBruger>
</ns:EjerBrugerSamling>
<ns:SynResultatStruktur>
<ns:SynResultatSynsType>RegistreringsSyn</ns:SynResultatSynsType>
<ns:SynResultatSynsDato>2011-02-25+01:00</ns:SynResultatSynsDato>
<ns:SynResultatSynsResultat>Godkendt</ns:SynResultatSynsResultat>
<ns:SynResultatSynStatus>Aktiv</ns:SynResultatSynStatus>
<ns:SynResultatSynStatusDato>2011-02-25+01:00</ns:SynResultatSynStatusDato>
</ns:SynResultatStruktur>
<ns:KoeretoejRegistreringStatus>Afmeldt</ns:KoeretoejRegistreringStatus>
<ns:KoeretoejRegistreringStatusDato>2010-11-19T00:00:00.000+01:00</ns:KoeretoejRegistreringStatusDato>
</ns:Statistik>
</ns:StatistikSamling>
</ns:ESStatistikListeModtag_I>
ns:Statistik contains data for one row. ns:Statistik should appear 6-8 mio times in the document.