首頁 資料庫 mysql教程 Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

Jun 01, 2016 pm 01:07 PM

Opera

In this blog post regardingMySQL for Excelnew features included in the 1.2.x versions family, we are going to talk about a new option that is used along withEditMySQLDataoperations; very useful when editing data in a multi-user environment. If you are not familiar with editingMySQLdata it is very advisable that you visit our thorough blog post about that topic: How To - Guide to editingMySQLdata withinExcel.

Remember you can install the latest GA or maintenance version using theMySQL Installeror optionally you can download directly any GA or non-GA version from theMySQL Developer Zone.

MySQL for Excel allows inserting, deleting and updating a table's rows usingExcelas a friendly front-end; a snapshot of the selectedMySQLtable is imported into aExcelworksheet and the Edit Session works with that detached copy of the data. Any changes done to that copy are translated into SQL statements that are applied against the selected MySQLtable. So far, so good.

In a multi-user environment, more than 1 person may be performing changes to the exact same records on a specificMySQLtable meaning the changes done by one person can be overwritten by another unless records are explicitly locked. By designMySQL for Exceldoes not lock a table when its data is imported to open an Edit Session because it is simply not practical, the session may be left open by a user for an unknown amount of time which can be very long, hence the disconnected nature of the Edit Session.

In all previous 1.x versions what could happen if 2 different persons were editing the exact same MySQL table would be the following as illustrated in the image below:

  1. User 1 (orange) opens an Edit Session against a MySQL table.
  2. User 2 (purple) also opens an Edit Session against the same MySQL table.
  3. User 2 modifies a record where C1 =1, modifies C2 =b, C3 =jand C4 =z, then commits the modifications.
  4. User 1 modifies the same record where C1 =1, modifies C2 =w, then commits that single modification.
  5. User 2 retrieves again from the database the record where C1 =1and notices C2 =wand is left wondering why since he expected it to have a value ofb.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

InMySQL for Excel1.2.0 we introduced a new global option to allow optimistic updates to be used on Edit Sessions to avoid overwriting any data that may have been modified by another user between the moment the Edit Session retrieved/refreshed the data from the database and the moment the Edit Session changes are committed. The Global Options dialog can be accessed from the Optionsbutton located in the Schema Selection panel or the DB Objects Selection one as shown below.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQLOptimistic updates for Edit Data operations in MySQL for Exc_MySQL

After clicking onOptionstheGlobal Advanced Optionsdialog will appear, under theSQL Queries Optionssection there is an option calledUse optimistic updates on all Edit Data sessionsthat if checked (which is by default) it will prevent the unintentional overwriting we mentioned above on all Edit Sessions inMySQL for Excel.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

The use of optimistic updates can also be turned on/off for all Edit Sessions or a specific one by right-clicking the Edit Session floating dialog and selecting from the context menuUse Optimistic Update  For all sessionsorFor this sessionrespectively.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

To understand better the mechanism of how the unintentional overwriting is done inMySQL for Excelwe can take a look at the SQL statements generated without and with optimistic updates turned on.  As an example, lets say we have an Edit Session open for theMySQLtableactor_copy, we turn off optimistic updates for this single session (unchecking the option in the screenshot above), and then we change some data as we can see in the screenshot below.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

Now having turned on thePreview SQL statements before they are sent to the serverglobal option (look at the screenshot with the global options up above) we can inspect the SQL statements generated byMySQL for Excelto apply the modifications after clickingCommit Changes.  In the screenshot below you can notice how the WHEREclause of theUPDATEstatements reference just the primary key columns of the table. We will clickCanceland not commit these changes.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

If then we turn back on optimistic updates for this Edit Session, and clickCommit Changesagain we will be able to see how the SQL statements for the same modifications look like using optimistic updates. In the screenshot below you can notice how the WHEREclause of theUPDATE statements reference all columns in the table, this way if any value of a record was changed by another user, the record will not be found and that UPDATE statement will not do anything.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

Lets say that before we hitApplyanother user is making modifications to theactor_copytable usingMySQL Workbench, and they change thelast_name column's value from"LEWIS"to"LOPEZ"of the record whereactor_id=4, and commit the change as seen in the screenshot below.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

Then we commit our changes inMySQL for Excel. Since another user committed a change on the record whereactor_id=4, theWHEREclause of the firstUPDATEstatement generated with optimistic updates turned on (see 2 screenshots above) will not find the record it was supposed to, and as we expected that change will not be unintentionally overwritten by the changes done inMySQL for Excel.  The cells that encountered optimistic updates conflicts will be colored orange and the information dialog that displays the operation results will show the conflicts as warnings as you can see below.

Optimistic updates for Edit Data operations in MySQL for Exc_MySQL

At this point all non-conflicting changes are committed to the database, but the conflicting changes are not. In order to fix the conflicts we need to locate the orange colored cells that depict the conflicting data, retrieve a fresh snapshot of data from the database by clickingRevert Dataon the Edit Session dialog thenRefresh Data from DB, then re-apply our changes on the conflicting cells and commit those changes again.

Optimistic updates makes Edit MySQL Data operations inMySQL for Excelmore friendly in multi-user environments and can prevent some data updating concurrency troubles. We hope you give this and the other new features inMySQL for Excela try!

Remember that your feedback is very important for us, so drop us a message and follow us:

  • MySQL on Windows (this) Blog:https://blogs.oracle.com/MySqlOnWindows/
  • MySQL for Excel forum:http://forums.mysql.com/list.php?172
  • Facebook: http://www.facebook.com/mysql
  • YouTube channel:https://www.youtube.com/user/MySQLChannel

Cheers!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

如何使用Alter Table語句在MySQL中更改表? 如何使用Alter Table語句在MySQL中更改表? Mar 19, 2025 pm 03:51 PM

本文討論了使用MySQL的Alter Table語句修改表,包括添加/刪除列,重命名表/列以及更改列數據類型。

如何為MySQL連接配置SSL/TLS加密? 如何為MySQL連接配置SSL/TLS加密? Mar 18, 2025 pm 12:01 PM

文章討論了為MySQL配置SSL/TLS加密,包括證書生成和驗證。主要問題是使用自簽名證書的安全含義。[角色計數:159]

哪些流行的MySQL GUI工具(例如MySQL Workbench,PhpMyAdmin)是什麼? 哪些流行的MySQL GUI工具(例如MySQL Workbench,PhpMyAdmin)是什麼? Mar 21, 2025 pm 06:28 PM

文章討論了流行的MySQL GUI工具,例如MySQL Workbench和PhpMyAdmin,比較了它們對初學者和高級用戶的功能和適合性。[159個字符]

您如何處理MySQL中的大型數據集? 您如何處理MySQL中的大型數據集? Mar 21, 2025 pm 12:15 PM

文章討論了處理MySQL中大型數據集的策略,包括分區,碎片,索引和查詢優化。

說明InnoDB全文搜索功能。 說明InnoDB全文搜索功能。 Apr 02, 2025 pm 06:09 PM

InnoDB的全文搜索功能非常强大,能够显著提高数据库查询效率和处理大量文本数据的能力。1)InnoDB通过倒排索引实现全文搜索,支持基本和高级搜索查询。2)使用MATCH和AGAINST关键字进行搜索,支持布尔模式和短语搜索。3)优化方法包括使用分词技术、定期重建索引和调整缓存大小,以提升性能和准确性。

如何使用Drop Table語句將表放入MySQL中? 如何使用Drop Table語句將表放入MySQL中? Mar 19, 2025 pm 03:52 PM

本文討論了使用Drop Table語句在MySQL中放下表,並強調了預防措施和風險。它強調,沒有備份,該動作是不可逆轉的,詳細介紹了恢復方法和潛在的生產環境危害。

您如何用外國鑰匙代表關係? 您如何用外國鑰匙代表關係? Mar 19, 2025 pm 03:48 PM

文章討論了使用外國密鑰來代表數據庫中的關係,重點是最佳實踐,數據完整性和避免的常見陷阱。

如何在JSON列上創建索引? 如何在JSON列上創建索引? Mar 21, 2025 pm 12:13 PM

本文討論了在PostgreSQL,MySQL和MongoDB等各個數據庫中的JSON列上創建索引,以增強查詢性能。它解釋了索引特定的JSON路徑的語法和好處,並列出了支持的數據庫系統。

See all articles