Data Masking Broke Your Joins? How to De-identify Data and Keep Table Relationships

· DataMint · 6 min read

You masked the personal data in the development database, opened a screen, and the customer detail shows no accounts at all. The data is clearly there, but the join returns zero rows. Anyone who has built test data by hand has run into this at least once.

To give the conclusion first, it is because the values were changed separately in each table. When the same original value becomes a different value in each table, the relationships that ran through that value are cut. The fix follows from that. Make the same value become the same value wherever it is.

Why joins break

Take an old system where customers and accounts are linked by the resident registration number (RRN, Korea's national ID number). Many systems now use a surrogate key such as a customer number, but in systems that have been running for more than ten years, RRNs, business registration numbers and phone numbers are still in join conditions.

Original: customer and account are linked by the RRN (made-up sample values)
TableNameRRNAccount number
CUSTOMER홍길동900101-1234568-
ACCOUNT-900101-1234568110-234-567890

Run the usual approach on this, a script that puts a random value into each column, and you get the following.

Result of random replacement per table: the same person now has different numbers
TableNameRRNAccount number
CUSTOMER김○○731122-2059174-
ACCOUNT-850630-1740026492-018-337215
SELECT c.name, a.acct_no
FROM customer c
JOIN account a ON a.rrn = c.rrn;   -- 0 rows

Masking with asterisks is not much different. If you erase the second half, as in 900101-*******, everyone born on the same day gets the same value. This time the join does not break. Instead, unrelated rows attach to each other and the row count multiplies. It is less visible than zero rows, so it tends to be found even later.

It is not only joins that break

When relationships are cut, problems show up in places other than joins. In the order we have seen them most often:

  • Foreign keys cannot be recreated. The child table now has values that do not exist in the parent, so creating the FK fails.
  • Unique keys collide. If two different people happen to be changed to the same value, the UNIQUE constraint is violated. The larger the volume, the more likely it is.
  • Systems do not match each other. If the core banking system is converted with script A and the information system with script B, the same customer becomes a different person in the two systems. Interface tests cannot be run.
  • Values change every time you rebuild. The customer number in a test case registered last week does not exist in this week's database.

The fix: the same value always becomes the same value

Only one property is needed. If the originals are the same, the results must be the same. That holds whichever table the value is in, whichever database it is moved to, and whenever the job runs. If this property holds, there is no need to touch join conditions, because both sides change in the same way.

Result when the same value becomes the same value: the numbers changed, the relationship did not
TableNameRRNAccount number
CUSTOMER김서윤900101-1947305-
ACCOUNT-900101-1947305110-871-204593

There are broadly two ways to do it.

Keeping a mapping table

Build a table that pairs each original value with its replacement, and apply that table to every table. It is easy to understand and easy to build yourself. The mapping table is the problem, though. It is one more table containing every original RRN, so in trying to remove personal data you have created a new personal data table. Once volumes reach the hundreds of millions, the time spent looking up the table is not small either.

Calculating with a key

Without a mapping table, the result is calculated from a secret key and the original value. The same key and the same input always give the same result, so there is no table to keep. Without the key, the original cannot be worked out from the result, and only the key needs to be kept safe. This is the method we use.

What to check if you build it yourself

If you implement this with scripts, we recommend checking the five points below. Most of them are found late, after long use.

  • Is the same value stored in different notations? 9001011234568 and 900101-1234568 are the same to a person but different values to a script. The same goes for leading and trailing spaces and full-width characters.
  • Do two different values collapse into the same value? Numbers have to be changed one to one for unique keys to hold.
  • Are NULL and the empty string left as they are? Oracle treats the empty string as NULL, which is especially confusing when moving between databases.
  • Are FKs created after all the data is loaded? Depending on the load order, the parent may not exist yet.
  • Does running it again next month give the same result? If the key or seed changes, the test cases built so far become useless.

How DataMint Core does it

DataMint Core, the product we build, works by the "calculating with a key" method described above. It uses a different secret key for each customer, and the same value becomes the same value even across different tables and databases. A customer table in Oracle and an information system table in PostgreSQL still match each other when moved separately.

Step 3 of the DataMint Core job creation screen, with RRN, phone number and email transformation rules attached to the columns of a table
When you create a job, you set a rule for each column. The product looks at column names and comments and suggests rules first, and the person in charge confirms them. (The console is shown in Korean. The data on screen is demo data.)

Keys are created the same as in production too. PKs and UNIQUE constraints, and FKs as well, are created as they are in the target database, with FKs created after all tables are loaded. If an FK cannot be created because a parent is missing, the run is not failed. Instead, the job log records which key on which table did not match.

DataMint Core run detail screen showing rows read and rows loaded per table, with the requester and approver
Run results are recorded per table. If some rows could not be loaded because of their values, the counts are reported by reason. (The console is shown in Korean.)

Closing

If joins broke after masking, the problem is not the tool or the query but the way the values were changed. Instead of looking at columns one at a time, first look at where the same value is stored. If those values all change to the same value together, the relationships hold without being touched.

If you are still deciding how to build test data in the first place, also read how to automate the development database refresh.

  • #data masking
  • #de-identification
  • #test data
  • #referential integrity
  • #development database
  • #consistent masking

Reviewing how you handle test data?

Tell us how you do it today and what databases you run, and we will look at the options with you.

More posts