0

So I decided I want my image names stored in mysql. So I would save the "1" in in my mysql database.

Now so far I intend to name my iamges in just numbers, in autoincrement actually. But should I name my image? Because I heard mysql can be rather slow, and I don't want a bunch of images names in my database if it's going to make my database run that much slower. Especially since image names really aren't that important.

Also, would autoincrement make my database run faster, as opposed to manual numbering?

EDIT: Totally unrelated question. I notice some people/sites separate their images into smaller chunks. Like something that could easily be one image, is separated into multiple image files? I don't get that, especially since amazon image hositng service charge per "get". As in amazon charges per picture too. So why do people split up images? I have my assumptions but I'm sure there's more to it.

3 Answers 3

1

Uhm....not sure about the context of your question, but broadly speaking, MySQL is one of the fastest database engines you can get for moderate use (the paid for products like Oracle and MS SQL Server are usually better for extreme requirements). Storing the name as a string will not be noticably slower than storing it as an integer - but it would help to get more of an idea of the actual application. Auto increment is a sensible choice for automatically assigning a primary key; it guarantees uniqueness of the number even if two processes access the table at the exact same time. In terms of performance, again - I don't think you could measure the difference.

Broadly speaking, with database stuff like this, I'd recommend to build a logically clean implementation, create the right indexing structure, and optimize it as far as you can; then measure performance. If that performance is not satisfactory, work out alternatives. Worrying about the kind of thing you're asking risks optimizing things that are already lightning quick, at the expense of maintainability and may often introduce other, far more severe performance issues...

Sign up to request clarification or add additional context in comments.

3 Comments

Hmm, but I heard size of database would slow down the database. I used this example in my comment above but I'll put it here again: If all my records have long image names, like "butterfly-flying-eastwards-towards-tibet", "boy-questioning-teacher-about-middle-east-crisis" instead of just numbering pictures as "1" and "2", would it make my page run a lot slower? Especially if I have like 10000image names in my table, does it add up?"
@user657847: Neville K answered your questions. You probably won't see the performance difference between meaningful image names and auto-incrementing numbers. You'll appreciate the meaningful image names the first time you have to debug a problem. Get the system to work properly first, then worry about performance.
Yes, MySQL gets slower if the tables get huge - but typically, only if you get millions of records, rather than if the records themselves are big. If your file name fits in a varchar field, you'll almost certainly not see any difference between the integer or the varchar option. If you have to use a text field because your filename is so big, you will run into performance problems when searching. Of course, modern versions of MySQL support varchar columns up to 65K, so it's unlikely this will be a problem...
0

I'm trying to answer based on your clarification response. As there would technically be more data being stored, it would, technically, make it slower. If you are indexing the column that could have the filename, then that could also potentially cause a performance hit due to using up more memory. If or when that becomes a problem depends on how much memory your server has, etc.

In either case I suspect it's not anything you need to worry about right now and falls into the category of premature optimization. It's going to make so little of a difference that you will not notice a difference at this point unless I'm greatly underestimating your table sizes and/or traffic.

Here's an update for the second part. It depends on exactly what you're seeing, but I would lean towards it being one of a few things.

1) Some parts of the image may need to change dynamically and it allows just loading/changing the bit that needs to change rather than the whole image.

2) By sending a large image in smaller chunks of several images, it can cause the image to start displaying sooner on the client which gives the impression of better responsiveness and faster loading.

3) The website is from a template that was provided as a psd file. These are horrible things where someone makes an image of the website in photoshop or the like and then chops it up into a bunch of small images and then they get loaded separately into a table or divs.

1 Comment

Thank you! Perfect response! Also, can you please answer my EDIT question? (I assume stack users know everything hah)
0

It's not that clear from your question what you intend to do. But I feel I should share my experience.

I stored image filenames(profile picture of users) as strings in User table, in _profile_pic.jpeg convention. The problem was, since browsers cached the images, when a user changed his/her profile picture in Update Profile form, the same image showed up. Since the filename of the image is same, the browser thought it's the same resource and served from cache instead of getting it over the HTTP. So we ended up putting images to another table, with an auto increment field a primary key, and image filename renamed to the corresponding PK.

Auto increment will not strictly make your database faster, but you should still avoid man

1 Comment

That's actually quite useful, knowing making another table can be a solution to some problems. Anyways, but my question which I wasn't that clear about is, whether or not it's even worth naming images if it's going to slow down my pages a lot. Like if all my records have long image names, like "butterfly-flying", "boy-questioning teacher" instead of just numbering pictures as "1" and "2", would it make my page run a lot slower? Especially if I have like 100image names in my table, does it add up? Also, can you answer my edit question =p

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.