Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt: no home region error in explicit txn has no home region #99540

Open
michae2 opened this issue Mar 24, 2023 · 0 comments
Open

opt: no home region error in explicit txn has no home region #99540

michae2 opened this issue Mar 24, 2023 · 0 comments
Labels
A-multiregion Related to multi-region A-sql-optimizer SQL logical planning and optimizations. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-qa T-sql-queries SQL Queries Team

Comments

@michae2
Copy link
Collaborator

michae2 commented Mar 24, 2023

With enforce_home_region set, it seems that there is different behavior for single statements using implicit transactions vs. statements in explicit transactions. Here is a repro, using cockroach demo --global --nodes 9 --multitenant=false --insecure:

CREATE DATABASE d PRIMARY REGION "us-east1" REGIONS "europe-west1", "us-west1";
SHOW CREATE DATABASE d;
USE d;

CREATE TABLE abc (
  a INT,
  b INT,
  c INT,
  PRIMARY KEY (a),
  INDEX (b)
) LOCALITY REGIONAL BY ROW;
SHOW CREATE TABLE abc;

INSERT INTO abc (a, b, c, crdb_region) VALUES (1, 1, 1, 'europe-west1'), (2, 2, 2, 'us-west1');

SET enforce_home_region = on;
SET enforce_home_region_follower_reads_enabled = on;

-- assuming locality is 'us-east1'
SHOW LOCALITY;

-- when this statement runs in an implicit transaction, it fails, but does have a home region (which is reported)
SELECT a FROM abc WHERE a = 1 LIMIT 1;

-- when run in an explicit transaction, however, it fails but does *not* have a home region:
BEGIN;
SELECT a FROM abc WHERE a = 1 LIMIT 1;

Here's how it looks on current tip of master (v23.1.0-alpha.8-dev):

root@127.0.0.1:26257/d> SELECT a FROM abc WHERE a = 1 LIMIT 1;
  a
-----
  1
(1 row)
(error encountered after some results were delivered)
ERROR: Query is not running in its home region. Try running the query from region 'europe-west1'. For more information, see https://www.cockroachlabs.com/docs/stable/cost-based-optimizer.html#control-whether-queries-are-limited-to-a-single-region
SQLSTATE: XCHR1

root@127.0.0.1:26257/d> BEGIN;
BEGIN

Time: 0ms total (execution 0ms / network 0ms)

root@127.0.0.1:26257/d  OPEN> SELECT a FROM abc WHERE a = 1 LIMIT 1;
ERROR: Query has no home region. Try using a lower LIMIT value or running the query from a different region. For more information, see https://www.cockroachlabs.com/docs/stable/cost-based-optimizer.html#control-whether-queries-are-limited-to-a-single-region
SQLSTATE: XCHR2

Jira issue: CRDB-25921

@michae2 michae2 added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-qa A-sql-optimizer SQL logical planning and optimizations. A-multiregion Related to multi-region T-sql-queries SQL Queries Team labels Mar 24, 2023
@mgartner mgartner changed the title opt: with enforce_home_region, query in explicit txn has no home region opt: no home region error in explicit txn has no home region Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-multiregion Related to multi-region A-sql-optimizer SQL logical planning and optimizations. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-qa T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

1 participant