dstm2014 2015-08-12 11:08
浏览 39
已采纳

增加VARCHAR长度或处理php的问题?

I'm using joomla 3.4 and I have installed the sh404 component for sef urls. My database is utf8_general_ci and many of my urls are url encoded from greek, which result in some really long urls.

Today I noticed that some urls were broken, so after investigating, I realised that sh404 is storing the urls in VARCHAR(255) columns. Because of that, some urls (not many, but enough for me to notice out of 200k urls) are longer than what the column allows and are being stored incomplete. Apart from the obvious problem of the broken urls and the expected 500 server errors etc, this results in the same broken url to be stored repeatedly, since sh404 looks if it is stored before storing it and doesn't find it (as the stored one is broken). In one case I had the same url stored over 5000 times......

Now my question to you is this. Should I just increase the VARCHAR length to 500 (should be enough to hold any URL, even my most extreme cases and with 40 - 50 to spare), or should i change the logic of the component I use that generates these urls, by transliterating them, thus reducing the size of ALL of my urls to more than half? The downside to this is that I will still have to output all of the necessary Info in Greek and in order to do so I will have to execute a lot of str_replaces with php.

My urls are beng generated by a combination of some db fields that contain product info in Greek. Sh404 picks up the Greek urls and transliterates them to english, but the original url gets too long. If I change all of the fields to contain the same info, already transliterated then sh404 will store urls already in english, but db fields will also be in english, thus the str_replaces. The good thing is that these values are known and fixed, so I won't be needing any preg_replaces.

What do you think is better performance wise?

Ofcourse changing VARCHAR to 500 is a lot more simple, but I don't care taking the long road if it is gonna benefit my performance

  • 写回答

1条回答 默认 最新

  • dongpang9573 2015-08-12 11:18
    关注

    Depends on which verison of mysql you are using?

    If it is before MySQL 5.0.3 your changing varchar to 500 option will not work and you have to go the other way.

    If it is 5.0.3 or later version then yes, that changing varchar to 500 would work and it would have very minimal of performance effect compared to that of changing your logic all over your project.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单