Appearance
So với Oracle và SQL Server
Tình huống: bạn đang chọn hoặc di chuyển giữa PostgreSQL 18 / MySQL 8.4 và Oracle / SQL Server, và cần biết khác biệt nào là kỹ thuật thật. Oracle và SQL Server vẫn được dùng vì (a) khác biệt kỹ thuật thật (bảng dưới) và (b) lý do phi kỹ thuật: hợp đồng và SLA của vendor, code legacy PL/SQL hoặc T-SQL, ERP chỉ certify trên chúng, yêu cầu compliance, đội DBA sẵn có, SQL Server gắn với Active Directory, .NET, Azure, Power BI. Ưu thế kỹ thuật đã thu hẹp: PostgreSQL có pgvector và JSONB (xem Database-Specific Features). Mục này chỉ tra cứu; phần sâu của PG/MySQL nằm ở các mục đã link.
Mức xác nhận: đo = chạy trong Docker (PG 18.7, MySQL 8.4, Oracle Free 23ai, SQL Server 2022), doc = đã đọc trang chính thức, doc không nêu = đã đọc trang chính thức liên quan nhưng không thấy câu nói về tính năng đó, không đồng nghĩa với "không có"; kiểm release notes trước khi dùng làm căn cứ.
Bảng 1: index và tối ưu truy vấn
| Tính năng | Oracle | SQL Server | PG 18 / MySQL 8.4 dùng gì | Mức xác nhận |
|---|---|---|---|---|
| Bitmap index (cột ít giá trị) | Có (CREATE BITMAP INDEX), kèm bitmap join index; không hợp OLTP | Doc không nêu bitmap index: trang Index Architecture and Design Guide liệt kê loại index Clustered or nonclustered, Columnstore or rowstore, Hash or nonclustered for memory-optimized tables, không có bitmap | PG: không có loại index bitmap, pg_am chỉ có brin, btree, gin, gist, hash, spgist; plan có Bitmap Heap Scan là bước ghép tạm thời. MySQL 8.4: CREATE BITMAP INDEX trả ERROR 1064 syntax error | đo (PG, MySQL 8.4.13, Oracle: ví dụ 1; PG: create index ... using bitmap báo access method "bitmap" does not exist); doc (SQL Server, https://learn.microsoft.com/en-us/sql/relational-databases/sql-server-index-design-guide: trang không nhắc bitmap); doc (Oracle: "bitmap indexes are not appropriate for many OLTP applications") |
| Index-organized table / clustered index | IOT (ORGANIZATION INDEX) | Clustered index | MySQL InnoDB luôn clustered theo PK (InnoDB Clustered Index); PG dùng heap, có lệnh CLUSTER sắp xếp một lần, không duy trì | doc (Oracle: "An index-organized table is a table stored in a variation of a B-tree index structure."); phần PG/MySQL xem mục link |
| Reverse key index | Có | Doc không nêu reverse key index (index design guide không liệt kê) | PG/MySQL: doc không nêu loại index này, dùng hash index hoặc UUID cho ghi phân tán | doc (Oracle: "A reverse key index is a type of B-tree index that physically reverses the bytes of each index key") |
| Function-based index | Có | Computed column + index | PG: expression index. MySQL 8.4: functional key part | doc (Oracle: "A function-based index computes the value of a function or expression involving one or more columns and stores it in an index.") |
| Columnstore + batch mode | Database In-Memory (cột trong RAM) | Columnstore index + batch mode | PG/MySQL: đo không thấy columnstore trong core (PG pg_am chỉ brin, btree, gin, gist, hash, heap, spgist; pg_available_extensions của image không có tên chứa column/citus/cstore; MySQL information_schema.engines không có engine cột), dùng extension hoặc DB khác | đo (SQL Server: ví dụ 2; PG 18.7 và MySQL 8.4 phía core); doc (Oracle: "The IM column store maintains copies of tables, partitions, and individual columns in a compressed columnar format that is optimized for rapid scans."; là option cấp phép riêng: "Database In-Memory features require the Oracle AI Database In-Memory option."; SQL Server 2022: Columnstore có ở mọi edition) |
| Plan history và ép plan | AWR, SQL Plan Management | Query Store + plan forcing | PG: pg_stat_statements (chỉ thống kê, không lưu plan, không ép plan); auto_explain | doc (Oracle AWR: "AWR collects, processes, and maintains performance statistics for problem detection and self-tuning purposes."; SQL plan management: "SQL plan management enables the optimizer to automatically manage execution plans, ensuring that the database uses only known or verified plans."); doc (Query Store: "Query Store automatically captures a history of queries, plans, and runtime statistics"); đo (pg_stat_statements có trong image PG 18.7) |
| Adaptive / Intelligent Query Processing | Adaptive plans, statistics feedback | IQP: memory grant feedback, adaptive joins, batch mode on rowstore; theo bảng editions 2022, batch mode adaptive joins, batch mode memory grant feedback, batch mode on row store, cardinality estimate feedback chỉ Enterprise (Standard No), còn parameter sensitive plan optimization và scalar UDF inlining có ở cả Standard | PG 18 có "skip scan" cho B-tree nhiều cột; doc PG không nêu phản hồi plan tự động tương đương | doc (SQL Server IQP: danh sách tính năng theo compatibility level; PG: "Allow skip scans of btree indexes"); doc (Oracle: "An adaptive query plan enables the optimizer to make a plan decision for a statement during execution."; "A form of reoptimization known as statistics feedback (formerly known as cardinality feedback) automatically improves plans for repeated queries that have cardinality misestimates."); doc (SQL Server 2022, bảng editions, mục Intelligent query processing: Batch mode adaptive joins Enterprise Yes, Standard No) |
| In-memory OLTP | Database In-Memory | In-Memory OLTP (bảng memory-optimized) | PG: bảng heap trên đĩa, nhanh nhờ buffer pool. MySQL: bảng InnoDB trên đĩa; engine MEMORY có sẵn (đo information_schema.engines: YES), doc không so với In-Memory OLTP. Lưu ý Database In-Memory của Oracle là cột nén trong RAM, khác In-Memory OLTP của SQL Server (bảng memory-optimized) | doc (SQL Server: "Memory-optimized tables are used for storing user data. You declare a table to be memory-optimized at create time."); doc (Oracle: "Oracle AI Database In-Memory (Database In-Memory) is a suite of features that greatly improves performance for real-time analytics and mixed workloads."; "Although OLTP applications do not benefit from accessing data in the IM column store, the dual-memory format can indirectly improve OLTP performance."); doc (SQL Server 2022 bảng editions: In-Memory OLTP Yes ở Enterprise, Standard, Web); đo (MySQL engine MEMORY) |
| Rebuild index online | ALTER INDEX ... REBUILD ONLINE | ALTER INDEX ... REBUILD WITH (ONLINE = ON); ONLINE = ON chỉ có ở Enterprise, Standard không có (SQL Server 2022 và 2025) | PG: REINDEX CONCURRENTLY. MySQL InnoDB: tạo hoặc xoá secondary index là in place, không chặn DML | doc (PG: "rebuild the index without taking any locks that prevent concurrent inserts, updates, or deletes"; MySQL: "The table remains available for read and write operations while the index is being created."); doc (SQL Server 2022 và 2025, bảng editions: dòng "Online index create and rebuild" Enterprise Yes, Standard No) |
Bảng 2: HA, bảo mật, vận hành
| Tính năng | Oracle | SQL Server | PG 18 / MySQL 8.4 dùng gì | Mức xác nhận |
|---|---|---|---|---|
| Nhiều instance cùng truy cập một database | RAC (shared storage) | Failover Cluster Instance dùng shared storage nhưng chỉ một node chạy dịch vụ tại một thời điểm; Availability Group thì mỗi replica giữ bản sao riêng | Doc không nêu tương đương RAC active-active trên một bản dữ liệu chung; PG/MySQL scale đọc bằng replica (Replication & Failover Scenarios) | doc (Oracle: "Oracle Real Application Clusters (Oracle RAC) enables multiple database instances running on separate servers to access one shared database"); doc (SQL Server FCI: "Unlike an availability group, an FCI must use shared storage among all nodes of the FCI for database and log storage."; "At any time, only the resource group owner (and no other node in the FCI) is running its respective SQL Server services"; AG: "Each availability replica hosts a copy of the availability databases in the availability group."); PG/MySQL: doc không nêu tính năng nhiều instance ghi cùng một bản dữ liệu chung |
| Standby và failover | Data Guard, Active Data Guard | Always On Availability Groups (đầy đủ chỉ Enterprise; Standard chỉ có Basic AG: 2 replica, 1 database) | PG: streaming và logical replication, thêm Patroni để failover tự động. MySQL: replication, Group Replication | doc (Oracle: "Oracle Data Guard provides a comprehensive set of services that create, maintain, manage, and monitor one or more standby databases"; MySQL: "MySQL Group Replication enables you to create elastic, highly-available, fault-tolerant replication topologies."); doc (SQL Server 2022 và 2025: bảng editions ghi Always On availability groups Enterprise Yes, Standard No; Basic availability groups Standard Yes, hai replica, một database; "A basic availability group supports a failover environment for a single database."); PG xem WAL & Replication Deep Dive |
| Xem lại dữ liệu quá khứ | Flashback Query, Flashback Table, Flashback Database | Temporal tables (system-versioned) | PG: PITR từ base backup + WAL (khôi phục cả cluster); đo: select ... for system_time as of báo syntax error trên PG 18.7. MySQL 8.4: cũng ERROR 1064 với FOR SYSTEM_TIME AS OF (đo). PG 18 có WITHOUT OVERLAPS cho khoá theo khoảng thời gian, không phải lịch sử tự động | đo (Oracle: ví dụ 3); doc (PG 18: "specified by WITHOUT OVERLAPS for PRIMARY KEY and UNIQUE"; SQL Server: "A system-versioned temporal table is a type of user table designed to keep a full history of data changes, allowing point-in-time analysis."); doc (Oracle Flashback Query: "retrieve data for an earlier time that you specify with the AS OF clause of the SELECT statement."; Flashback Table: "restore a table to its state at a previous point in time."; Flashback Database: "quickly return the database to an earlier point in time, by using the recovery area."); doc (SQL Server 2022 bảng editions: Temporal Yes ở mọi edition) |
| Mã hoá dữ liệu lưu trữ | Transparent Data Encryption | TDE (Enterprise, Standard); Always Encrypted (mã hoá phía client, có ở mọi edition theo bảng editions 2022) | MySQL 8.4 Community: InnoDB mã hoá tablespace, redo, undo với component_keyring_file; keyring tập trung (Vault, KMS) chỉ ở Enterprise. PG: pgcrypto mã hoá ở cột; mã hoá lưu trữ làm ở tầng file system hoặc block của hệ điều hành, trang Encryption Options không nêu TDE nguyên bản | doc (MySQL: "InnoDB supports data-at-rest encryption for file-per-table tablespaces, general tablespaces, ..."); đo (pgcrypto có trong image); doc (PG 18, Encryption Options, mục Data Partition Encryption: "Storage encryption can be performed at the file system level or the block level."; trang không có mục TDE) |
| Row-level security | Virtual Private Database; Database Vault | Row-Level Security | PG: row security policy có sẵn. MySQL 8.4: không có RLS khai báo (CREATE POLICY báo lỗi cú pháp), dùng view hoặc stored procedure | doc (Oracle VPD: "A VPD policy uses a function to generate the dynamic WHERE clause, and a policy to attach the function to objects to protect."; Database Vault: "Oracle Database Vault provides fine-grained access control to your sensitive data, including protecting data from privileged users."); doc (SQL Server 2022: Row-level security Yes ở mọi edition); doc (PG: "tables can have row security policies that restrict, on a per-user basis, which rows can be returned"); đo (MySQL 8.4.13: CREATE POLICY p ON t USING (1=1) trả ERROR 1064 syntax error) |
| Audit | Unified Auditing | SQL Server Audit | PG: log_statement, extension pgaudit (không có trong image mặc định). MySQL: Enterprise Audit chỉ bản Enterprise | doc (Oracle Unified Auditing: "writes the audit records into a single consolidated unified audit trail"); doc (SQL Server 2022: Server audit và Database audit Yes ở mọi edition); doc (MySQL: "MySQL Enterprise Audit is an extension included in MySQL Enterprise Edition, a commercial product."); đo (pgaudit không có trong pg_available_extensions của image 18.7) |
| Giới hạn tài nguyên theo nhóm | Resource Manager | Resource Governor (trước SQL Server 2025 chỉ có ở Enterprise và Developer) | PG: doc không nêu Resource Manager trong core. MySQL 8.4: có resource group (đo: information_schema.resource_groups có USR_default, SYS_default) (phạm vi giới hạn của resource group: xem doc MySQL 8.4 trước khi so với Resource Manager). Cả hai: giới hạn bằng role (statement_timeout, CONNECTION LIMIT) hoặc connection pooler | doc (SQL Server: "Resource governor lets you reserve or limit the amount of CPU, memory, and physical I/O that user query workloads can use."; SQL Server 2025 bảng editions: Resource governor Enterprise Yes, Standard Yes, 2022: Standard No; Oracle: "Oracle Database Resource Manager (the Resource Manager) enables you to manage multiple workloads within a database that are contending for system and database resources."); đo (MySQL resource_groups) |
| Đẩy lọc xuống storage | Exadata Smart Scan (phần cứng riêng) | Doc không nêu tương đương Smart Scan (bảng editions có dòng "Integrated acceleration and offloading" là tính năng khác, chưa đối chiếu) | Doc không nêu tương đương | doc (Oracle: "Exadata Smart Scan offloads data search and retrieval processing to the Exadata storage servers."); doc không nêu (SQL Server, PG/MySQL: không tìm thấy trong các trang đã đọc) |
| Partitioning nâng cao | Interval, reference, composite | Partition function + scheme | PG: declarative range, list, hash (Partitioning Internals); doc PG không nêu interval tự tạo partition mới trong core (chưa dò release notes từng bản). MySQL 8.4: trang Partitioning Types liệt kê RANGE, LIST, HASH, KEY, không mô tả tạo partition tự động; "Some database systems support explicit date partitioning, which MySQL does not implement in 8.4." | doc (Oracle: "Interval partitioning instructs the database to automatically create partitions of a specified interval"; "Reference partitioning enables the partitioning of two tables that are related to one another by referential constraints."; "Composite partitioning is a combination of the basic data distribution methods."); doc (SQL Server 2022 bảng editions: Table and index partitioning Yes ở mọi edition; Partitioned table parallelism Yes ở Enterprise, Standard, Web); doc (MySQL 8.4: "This type of partitioning assigns rows to partitions based on column values falling within a given range.") |
Ví dụ 1: Oracle bitmap index so với B-tree (minh hoạ, không chạy độc lập trên PG)
500 000 hàng, cột status có 5 giá trị. Oracle không cho tạo bitmap và B-tree trên cùng danh sách cột của một bảng (ORA-01408), nên so trên hai bản sao.
sql
CREATE BITMAP INDEX ix_bm ON orders(status); -- bảng orders
CREATE INDEX ix_bt ON orders_bt(status); -- bản sao orders_btKết quả đo (Oracle Free 23ai, Docker): bitmap 512 KB, B-tree 10 240 KB, cả hai trả COUNT(*) = 100000 cho status = 'NEW'. Bitmap nhỏ gấp 20 lần; Oracle ghi "bitmap indexes are not appropriate for many OLTP applications" vì một khoá bitmap trỏ tới nhiều hàng nên DML khoá hết các hàng đó ("Because a key points to many rows, DML on indexed data typically locks all of these rows"), nên chỉ hợp bảng đọc nhiều (DW).
Ví dụ 2: SQL Server columnstore (minh hoạ, không chạy độc lập trên PG)
sql
CREATE CLUSTERED COLUMNSTORE INDEX cci ON f_cs; -- f_cs: bản sao của f_row
SELECT cat, SUM(amt) FROM f_cs GROUP BY cat OPTION (MAXDOP 1);Kết quả đo (SQL Server 2022 qua emulation amd64 trên Apple Silicon, 2 triệu hàng): rowstore 244 MB, columnstore 5 MB; GROUP BY CPU 292 ms (rowstore) so với 5 ms (columnstore). Số tuyệt đối lệch do emulation, tỉ lệ mới đáng nhìn.
Ví dụ 3: Oracle Flashback Query (minh hoạ, không chạy độc lập trên PG)
sql
SELECT dbms_flashback.get_system_change_number FROM dual; -- ghi lại SCN
UPDATE acct SET bal = 0 WHERE id = 1;
COMMIT;
SELECT bal FROM acct AS OF SCN &scn; -- &scn = SCN đã ghi ở trênKết quả đo: bal hiện tại 0, truy vấn AS OF SCN trả 100. Cần chờ vài giây sau khi tạo bảng (DDL làm mất undo của bảng; AS OF ngay sau DDL báo ORA-01466). Trên PG, lấy lại giá trị cũ cần PITR cả cluster hoặc tự giữ bảng lịch sử bằng trigger.
Phải nhớ:
- Lý do chọn Oracle hoặc SQL Server thường là hợp đồng và hệ sinh thái, không phải index; về index thuần, bảng 1 cho thấy PG 18 và MySQL 8.4 có tương đương cho expression index, rebuild online và skip scan; chỗ thiếu rõ là bitmap index và columnstore trong core.
- Khác biệt kỹ thuật đã có số đo hoặc doc: columnstore (SQL Server), Flashback Query và bitmap index (Oracle); PG và MySQL 8.4 không có loại index bitmap (đo: lỗi khi tạo), SQL Server doc không liệt kê bitmap trong các loại index.
- Ô ghi
doc không nêunghĩa là các trang đã đọc không nêu tính năng đó, không phải bằng chứng là không có; kiểm release notes của đúng phiên bản trước khi dùng làm căn cứ quyết định.