简体   繁体   English

哪种方式处理更快?

[英]Which way would be faster to process?

A lil background info 法律背景信息

At the moment I have a script that parses a page on a site (not controlled by me) into a mysql database for a game (Getting ingame attack logs). 目前,我有一个脚本,可将站点(不受我控制)上的页面解析到用于游戏的mysql数据库中(获取游戏中攻击日志)。 I've recently decided I wanted to upgrade this faster and I've completely recoded the parser so that it stores the data into an array. 我最近决定要更快地升级它,并且我已经完全解析了解析器,以便将数据存储到数组中。 Now onto the basis of my question: 现在根据我的问题:

My first version currently has around 50 columns, one for each unit times by how many a user lost/has left and a few other bits and pieces - these often go unused if the user doesn't actually lose a unit or doesn't loose a unit of that type. 我的第一个版本目前大约有50列,每单位乘以一个用户丢失/遗失的数量以及其他一些零碎的内容-如果用户实际上没有丢失或不松动,则这些列通常不使用该类型的单位。 Now if I was to JSON encode the array and literally stick that into the database 现在,如果我要对数组进行JSON编码并将其按字面意义粘贴到数据库中

1) will that be faster than the current one when inserting? 1)插入时会比当前的快吗?

2) Lets say I need to get that data back on the front page and show 100 results(Only a summary is needed so only 3 columns selected on the first way), if I was to do the first way I could show the data with one select and while loop it, would that be slower or faster than me selecting it from the db, then decoding it and processing it? 2)假设我需要在首页上获取该数据并显示100个结果(仅需要摘要,因此第一种方法仅选择3列),如果我要进行第一种方法,则可以使用一个选择并同时循环它,会比我从数据库中选择它然后解码并处理它慢还是快?

(Also if you know of a better way, don't hesitate to say :) - or if I should do a mix of the two) (另外,如果您知道更好的方法,请不要犹豫:)-否则我应该将两者混合使用)

The issue isn't so much with the inserting, which you only do once per record - but in the reading. 插入的问题并不多,插入每条记录只需要执行一次,但在阅读中却没有。 You will lose of all MySQLs data-processing powers as you will just have a JSON lump sat in a big text field. 您将失去所有MySQL的数据处理能力,因为在大文本字段中只有一个JSON块。

It would be much more performant to be able to select the records you need from the database using a MySQL query than it would be getting all records from the database and looping around them in memory. 能够使用MySQL查询从数据库中选择所需记录的性能要比从数据库中获取所有记录并在内存中循环遍历要好得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM