将列表存入MySQL_如何有效地将动态列表存储到MySQL列中?

bd96500e110b49cbb3cd949968f18be7.png

I want to store a list of numbers along with some other fields into MySQL. The number of elements in the list is dynamic (some time it could hold about 60 elements)

Currently I'm storing the list into a column of varchar type and the following operations are done.

e.g. aList = [1234122433,1352435632,2346433334,1234122464]

At storing time, aList is coverted to string as below

aListStr = str(aList)

and at reading time the string is converted back to list as below.

aList = eval(aListStr)

There are about 10 million rows, and since I'm storing as strings, it occupies lot space. What is the most efficient way to do this?

Also what should be the efficient way for storing list of strings instead of numbers?

解决方案

Since you wish to store integers, an effective way would be to store them in an INT/DECIMAL column.

Create an additional table that will hold these numbers and add an ID column to relate the records to other table(s).

Also what should be the efficient way

for storing list of strings instead of

numbers?

Beside what I said, you can convert them to HEX code which will be very easy & take less space.

Note that a big VARCHAR may influence badly on the performance.

VARCHAR(2) and VARCHAR(50) does matter when actions like sotring are done, since MySQL allocates fixed-size memory slices for them, according to the VARCHAR maximum size.

When those slices are too large to store in memory, MySQL will store them on disk.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值