首页 \ 问答 \ MySQL:使用一个表快速填充另一个表(MySQL: Use one table to fill another quickly)

MySQL:使用一个表快速填充另一个表(MySQL: Use one table to fill another quickly)

我正在运行MySQL(对我而言是新语言),并且正在尝试合并两个表,如此论坛上所描述的那样令人作呕。 我从另一个线程中获取了似乎最受欢迎的答案,并且它有效:

  ALTER TABLE table1 ADD col3 varchar( 30 ) NOT NULL; 
  UPDATE table1,table2
  SET table1.col3=table2.col3
  WHERE table1.col1 = table2.col1 AND table1.col2 = table2.col2

问题是性能 - 这需要15秒来更新500条记录,显然需要几个小时来更新~50k记录(在我的Macbook上)。 我怎样才能让这个更快?


I am running MySQL (new language for me) and am trying to merge two tables as described ad nauseam on this forum. I took what seems to be the most popular answer from another thread, and it works:

  ALTER TABLE table1 ADD col3 varchar( 30 ) NOT NULL; 
  UPDATE table1,table2
  SET table1.col3=table2.col3
  WHERE table1.col1 = table2.col1 AND table1.col2 = table2.col2

The problem is performance -- this takes 15 s to update 500 records, and apparently hours to update ~50k records (on my Macbook). How can I make this MUCH faster?


原文:https://stackoverflow.com/questions/36050912
更新时间:2023-07-19 06:07

最满意答案

Wyatt Barnett的回答让我尝试只为用户点击“刷新”按钮。 然后我使用setInterval每5分钟触发一次刷新按钮:

    <script src="../../scripts/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            setInterval("$('#RefreshFormButton').click()", 300000);
        });
    </script>

Wyatt Barnett's answer made me try just clicking the Refresh button for the user. And then I used setInterval to trigger the Refresh Button click every 5 minutes:

    <script src="../../scripts/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            setInterval("$('#RefreshFormButton').click()", 300000);
        });
    </script>

相关问答

更多
  • 我个人更喜欢jQuery,原因如下: - 插件社区更加多样化,吸引了广泛背景的开发人员(而不仅仅是MS堆栈)。 对于MS-AJAX,你现在几乎受限于客户端的用于UI小部件的AJAX控件工具包。 我发现jQuery API远比MS AJAX提供的更适用于常见的客户端任务 鉴于缺乏WebForms MVC中的烟雾和镜像,您有时需要对DOM进行严格的控制才能做某些事情,jQuery提供的CSS选择器引擎确实可以帮助您做到这一点。 就MS AJAX在MVC中提供的内容而言,它可以为您提供一种快速“AJAXify”表 ...
  • 如果我理解你正在尝试做的事情,我的第一个答案将是否定的,你不能使用模型状态,因为它是通过和Ajax请求。 也许你可以模拟ModelState行为,以显示错误: 通过JSON传递List> (属性,消息)(这将要求您将modelErrors从modelState传递到新结构),并通过JS / jQuery完成Validation Summary的HTML构造我认为是杀死解决方案)。 如果您要访问服务器,并且出现任何错误,只需执行Html.Validati ...
  • 这可能是一种可行的方法: 在javascript中存储在全局变量中获取数据的时间。 每隔x分钟,您对一个以时间戳作为参数的动作方法进行javascript调用。 这可以使用Rony建议的jQuery Timer来完成。 action方法检查数据库以查看是否有任何更改,并返回一个简单的boolean 1/0。 如果且仅当数据发生更改时,您将从另一个操作方法获取新数据,并通知用户已检索到新数据。 This could be a possible way to do it: Store the time when ...
  • 例: 模型: public class MyViewModel { [Required] public string Foo { get; set; } } 控制器: public class HomeController : Controller { public ActionResult Index() { return View(new MyViewModel()); } [HttpPost] public ActionRes ...
  • 问题是,您在文档就绪事件上的"like"和"unlike" css类上注册了click事件。 因此它适用于当时DOM中存在的元素。 在ajax调用的success处理程序中,您正在将锚标记html重置为某个新标记,并且已注册的单击事件代码将无法使用此标记。 你应该做的是, on事件委托on使用jQuery来注册你的点击事件。 它适用于当前和未来的元素(动态注入DOM)。 所以改变你的代码 $("a.like").click(function () { //do the ajax call }); ...
  • data: {profile: profile},是两个片段不同的地方。 你可能想要data: profile 。 它们在这里也有所不同: dataType: "json" ,但是如果你的服务器正在返回json那就没关系。 $.ajax({ url: "/api/profile", type: "post", //dataType: "json", optional, you can keep it if you want. data: profile, succes ...
  • Wyatt Barnett的回答让我尝试只为用户点击“刷新”按钮。 然后我使用setInterval每5分钟触发一次刷新按钮: